Hey guys/girls...

I am looking to constantly check to see if a variables value has changed.
An example below might be simular

' If the value of this variable ever changes - perform some action
Dim str As String = ""

However, using a timer seems inefficient as I have multiple variables I want to monitor.

Any idea how I might go about doing this?

Thanks

Recommended Answers

All 3 Replies

Make your variable a class with an event.
Make your class:

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

Now in your main form create a textbox and button:

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

In your class you can also set a boolean wheather to activate the event or not.

Your awsome! This is not what I was looking for, more what I dreamed about!!! Thank you soooooo much.

Thank you veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.