Results 1 to 3 of 3

Thread: How do I add any stuff to an array?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    San Jose, CA
    Posts
    3

    Question 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.

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    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
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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:
    1. Private someStuff As Collection = New Collection()
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, _
    4.  ByVal e As System.EventArgs) Handles Button1.Click
    5.         somestuff.Add(TextBox1.Text)
    6.  
    7.     End Sub
    8.  
    9.     Private Sub Button2_Click(ByVal sender As System.Object, _
    10.  ByVal e As System.EventArgs) Handles Button2.Click
    11.         MsgBox(someStuff.Item(someStuff.Count).ToString)
    12.        'someStuff.Count returns the last item entered
    13.     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
  •  



Click Here to Expand Forum to Full Width