1,105,423 Community Members

ArrayList to ListBox

Member Avatar
jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

            [B]termListBox.Items.Add(users.Item(i))[/B]
        Next i

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

Member Avatar
martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

What is the error message?

Member Avatar
jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 63 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 6 [?]
 
0
 

try:

For i As Integer = 0 To users.Count -1
Member Avatar
jhonnyboy
Junior Poster in Training
97 posts since Jul 2008
Reputation Points: 1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
martonx
Junior Poster in Training
51 posts since May 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 8 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
waynespangler
Posting Pro in Training
461 posts since Dec 2002
Reputation Points: 63 [?]
Q&As Helped to Solve: 58 [?]
Skill Endorsements: 6 [?]
 
0
 

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.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article