On Visual Basics.NET, my form will be using two buttons and a text box. The first button will store whatever I put into the text box and the second button will display whatever was stored. How do I add stuff to an array? I'm doing something wrong.
Printable View
On Visual Basics.NET, my form will be using two buttons and a text box. The first button will store whatever I put into the text box and the second button will display whatever was stored. How do I add stuff to an array? I'm doing something wrong.
as you said you need a textbox and 2 buttons. This array can store up to 10 values(although this example only ever stores 1). Remember the first position to store values in an array is 0.Code:Dim intNumbers(9) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
intNumbers(0) = TextBox1.Text
TextBox1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(intNumbers(0))
End Sub
hope this helps
Nick
That won't work.
Since you haven't provided much information, I'm guessing this is basically a homework assignment, so excuse the lack of finesse in my solution:
What you probably want is a collection.
VB Code:
Private someStuff As Collection = New Collection() Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click somestuff.Add(TextBox1.Text) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click MsgBox(someStuff.Item(someStuff.Count).ToString) 'someStuff.Count returns the last item entered End Sub