user2764644
user2764644

Reputation: 21

how to observe changes in an array in vb .net

i have an array A, i just want to monitor the changes in that array, return the changed position of that array.

 myOldTextBox = myTextBox
            myTextBox = New TextBox() {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
            Dim i As Integer
            For i = 0 To myTextBox.Length - 1
                If myTextBox(i).Text <> myOldTextBox(i).Text Then
                    Dim fs As Integer
                    fs = farray.Length
                    farray(fs) = i
                End If

            Next i

i am newbie in vb .net. Thank you.

Upvotes: 0

Views: 189

Answers (3)

Gale_i
Gale_i

Reputation: 11

EDITED: (Didn't notice you were doing what I posted)

I would change the For loop to a Do While loop, because I have found issues when comparing substring in a For Loop, try it and see if that doesn't fix your problem...

(I've even tried Microsoft code that failed in for Loops w/ substrings)

Also, I'd HIGHLY suggest you use a MessageBox.Show(sMsg) or Debug.WriteLine(sMsg) to ENSURE that data is correct...

Upvotes: 0

Malcolm Salvador
Malcolm Salvador

Reputation: 1566

add a listbox, and whenever the if condition is satisfied, add content to the listbox

        myTextBox = New TextBox() {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5}
        Dim i As Integer
        For i = 0 To myTextBox.Length - 1
            If myTextBox(i).Text <> myOldTextBox(i).Text Then
                Dim fs As Integer
                fs = farray.Length
                farray(fs) = i

                Listbox1.items.add(Format(now,"yyyy-MM-dd hh:mm:ss") & _
                " array number changed: " & i
            End If

        Next i

Upvotes: 0

raf
raf

Reputation: 267

I don't believe you can do that.

For a regular variable I would suggest using get/set.

For an array, I would suggest creating a method to update the values, instead of setting the values directly (you can enforce this by making the array private and only giving it access through a get and set method).

In that method you can then do anything you want.

Pseudo code:

private _array
Public Function GetArray(ByVal key As String) As String
    return _array(key)
End Function

Public Function SetArray(ByVal key As String, ByVal val As String) as String
    _array(key) = val

   return val;
End Function

Upvotes: 2

Related Questions