Hello,
I'm wondering if I should take this personally.
I haven't quote grasped this whole "class" concept yet, but I'm working on it.
When following the instructions below, the "test" portion of this code: "test.variable"
has an underlined error that says that "test" is not declared.
If i remove the "test" word then the ".variable" shows not declared.
I'm using Visual Studios 8 if that makes any difference.
I have a pre-existing variable in a project that I would like to monitor for changes.
Any suggestions?
Re: Detect variable change.
Make your variable a class with an event.
Make your class:
VB.NET Syntax (Toggle Plain Text)
Public Class myVar
Private mValue As Integer
Public Event VariableChanged(ByVal mvalue As Integer)
Public Property Variable() As Integer
Get
Variable = mValue
End Get
Set(ByVal value As Integer)
mValue = value
RaiseEvent VariableChanged(mValue)
End Set
End Property
End Class
Public Class myVar Private mValue As Integer Public Event VariableChanged(ByVal mvalue As Integer) Public Property <strong class="highlight">Variable</strong>() As Integer Get <strong class="highlight">Variable</strong> = mValue End Get Set(ByVal <strong class="highlight">value</strong> As Integer) mValue = <strong class="highlight">value</strong> RaiseEvent VariableChanged(mValue) End Set End Property End Class
Now in your main form create a textbox and button:
VB.NET Syntax (Toggle Plain Text)
Public Class Form1
Private WithEvents test As New myVar
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
test.Variable = CInt(TextBox1.Text)
End Sub
Private Sub VariableChanged(ByVal NewValue As Integer) Handles test.VariableChanged
MessageBox.Show(NewValue)
End Sub
End Class