'Why does my Clear TexBox command makes the rest of my number in the listbox zero?

Every number is zero.

Hi, I’m fairly new to VisualStudio and I have this problem in my code:

What I have to do, is to fill an array (all the variables have to be local!) of three numbers and display the numbers in a listbox, when the array is full disable the button to add numbers and at the end display another array in other listbox but with the values divided by two (that’s another story tho).

It worked at first and I could add the numbers fine, but, I had to clear the textbox manually every time I wanted to add a number, so I tried to add the command

Me.txtAddNumber.Clear()

but after that every time I added a number, it appeared in the listbox as 0. What can I do to fix it?

My code right now is:

Private Sub btnAddToArray_Click(sender As Object e As EventArgs)Handles btnAddToArray.Click

Dim ArrayListOriginal(2) As Integer

Static Index As Integer = 0

Me.txtAddNumber.Clear()

ArrayListOriginal(Index) = Val(Me.txtNumToInput.Text)

lstOriginal.Items.Add(ArrayListOriginal(Index))

If 
Index = ArrayListOriginal.Lenght Then Me.btnToAddArray.Enabled = False
End If

End Sub

Thanks for your help!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source