0

How do I take the information I type in a text box and then store it into an array. For example I have array(6). I have text box lastName. I type the name 'Smith' into lastName and when I click buttonSubmit, that text box information is stored in array(0) and placed in listBox1.

Any help would be greatly appreciated. Maybe a link of general tips as to how I can achieve this feat. Thanks you!

2
Contributors
1
Reply
5
Views
5 Years
Discussion Span
Last Post by BitBlt
0

No real need to store it in an array...the ListBox control is, for all intents and purposes, an array. So, when the user clicks on the "Submit" button, just do this in the cmdSubmitButton_Click event procedure:

' Assumes some control names, so you'll have to change to match your project
Me.List1.AddItem Me.lastName.Text
' now be sure and clear the text box so you don't add the same thing twice
Me.lastName.Text = ""

You could also put a test in to check and see if there is any text in the text box first so you don't add blank lines. To reference the items, just use Me.List1.List(0), Me.List1.List(1), etc. or iterate through with an integer index.

You could even get fancier and iterate through the list to check for whether your new text already exists and hoist a message and bypass if it does. Last, if you want to limit the number of items in the list, just check the Me.List1.ListCount property and exit the sub if you overrun.

Edited by BitBlt: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.