954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ArrayList to ListBox

Hello everyone i am getting input from the user in the form of an inputbox. The inputbox then dumps the information into an arrayList which then i want my Listbox to be populated by the items within the arrayList.

so...

userName = InputBox -> arrayList.add(userName) - > Listbox.items.add(arrayList)

Here is some of my code.

userName = InputBox("Enter Name: ")

        Dim users As ArrayList = New ArrayList()
        users.Add(userName)

        For i As Integer = 0 To users.Count

            <strong>termListBox.Items.Add(users.Item(i))</strong>
        Next i


It gives me the error at the bold highlighted text. Any ideas?

jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 11
Solved Threads: 0
 

What is the error message?

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

It said something about out of bounds. Does the syntax look right?

jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 11
Solved Threads: 0
 

try:

For i As Integer = 0 To users.Count -1
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

That worked thanks :) I have another question. How can i load a form from another form? I tried form.show but the form came up and quit after a couple of seconds.

jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 11
Solved Threads: 0
 

What is your code for new form?
Perhaps you close the new form after show.
You can try form.showdialog too.

martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 10
Solved Threads: 8
 

Double click on the My Project. On the left hand side toward the bottom in the Shut Down Mode select "After last form closes".
If you don't then when you close the startup form the program ends.

waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 84
Solved Threads: 58
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You