I need to create a program that will allow me to enter 10 numbers into a list box through a input box. I need to use a For...Next loop to take in 10 numbers, adding each as they entered into the list box. Please help.
Printable View
I need to create a program that will allow me to enter 10 numbers into a list box through a input box. I need to use a For...Next loop to take in 10 numbers, adding each as they entered into the list box. Please help.
What have you done so far?
This is what i have so far. I can't figure out how to get the data i enter in the input box to show up in the list box?
Private Sub mnuEnterNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnterNumbers.Click
Dim userInput As String
Dim x, total As Integer
total = 0
For x = 1 To 10
userInput = InputBox("Enter a number.", "Input Needed")
total += x
Next x
'lstNumbers = userInput
End Sub
Please help.
We can't do your homework for you and if this is an exercise from a book you're using then there's not much point us doing it for you as you learn by doing. The rule to programming problems, as for most problems, is to divide and conquer. Don't look at the whole problem, but rather break into manageable pieces. Once you solve each subproblem you automatically solved the whole.
First things first. Can you use an InputBox to get a string from the user?
Then, can you put a string in a ListBox?
Then, can you make a For loop do the same thing 10 times?
Note that those three things are completely unrelated. They are all independent problems but if you can solve them then you can put the result together to solve your original problem.
If you want to add and item to a ListBox you call the Add method of the LisBox's Items property:VB Code:
myListBox.Items.Add(newItem)
Just a tip if surround your code with VBCODE & /VBCODE tags it easier to read your code.
VB Code:
listBox1.Items.Add(userInput)
Here it comes
Edit** as shown above.VB Code:
Private Sub mnuEnterNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEnterNumbers.Click Me.lstNumbers.Items.Clear() For i As Integer = 1 To 10 Me.lstNumbers.Items.Add(InputBox("Enter a number.", "Input Needed")) Next i End Sub
Jmcilhinney got 3 post in before I got 1 - speed racer!!!
Everyone here got a life in before I got any. :( ;)