Classes

  • Thread starter Thread starter James Proctor
  • Start date Start date
J

James Proctor

Hi there, im writting a class and when a varible changes
i would like it to call a routine. The thing is i dont
want to use a timer that checks the varible every second
or something. Is there some way that a piece of code can
do this?

Thanks

JP

(e-mail address removed)
http://www.ebmis.co.uk
 
If you implement the variables as a property, then you can execute any code
you wish in the "Set" part of the Property.

E.g.:
---------------------

' Variable used to store the value
Private mMyVariable as Integer

' Property used to access the value
Public Property MyVariable as Integer
Get
return mMyVariable
End Get
Set(ByVal Value as Integer)

mMyVariable = Value

' Run Custom code
DoStuff()

End Set
End Property


--------------------

Any time you want to access the variable, simply use the property instead of
the variable. (e.g. "Me.MyVariable = 10")

Beware of infinite loops if you change the varible from the "DoStuff()"
method.

Hope this helps,

Trev.
 
James Proctor said:
Hi there, im writting a class and when a varible changes
i would like it to call a routine. The thing is i dont
want to use a timer that checks the varible every second
or something. Is there some way that a piece of code can
do this?

Yes, write a property. In the property-set procedure, you can put the code
you need. But, what are you trying to accomplish? Maybe there's a "better"
approach.
 
Well thats what i though, but i was thinking along the
lines of in a socket class i would like to activate a
routine called datarecieved when the varible
TCPListener.pending changes to equal true. How could i
implement this?

JP

(e-mail address removed)
http://www.ebmis.co.uk
 
I take it you mean that you have a private variable of type TCPListener and
want to know when "TCPListener.pending" changes to true?

As TcpListener.Pending is a Function, not a propery, you can't watch it
without perodically calling it. I believe that you would probably be better
off looking to implement a multithreaded app where one thread calls
AcceptTcpClient and waits for a client to connect.

Have a look at the following for samples:

http://tinyurl.com/2dosd
http://tinyurl.com/383zg


Hope this helps,

Trev.
 
Back
Top