|
-
May 6th, 2003, 04:37 PM
#1
Thread Starter
New Member
How do I add any stuff to an array?
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.
-
May 6th, 2003, 04:46 PM
#2
Fanatic Member
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
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.
hope this helps
Nick
-
May 6th, 2003, 06:05 PM
#3
I wonder how many charact
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|