|
-
Oct 16th, 2006, 10:14 PM
#1
Thread Starter
New Member
Need help creating a program
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.
-
Oct 16th, 2006, 10:16 PM
#2
Re: Need help creating a program
What have you done so far?
-
Oct 16th, 2006, 10:25 PM
#3
Thread Starter
New Member
Re: Need help creating a program
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.
-
Oct 16th, 2006, 10:26 PM
#4
Re: Need help creating a program
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.
-
Oct 16th, 2006, 10:28 PM
#5
Re: Need help creating a program
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)
-
Oct 16th, 2006, 10:29 PM
#6
Fanatic Member
Re: Need help creating a program
Just a tip if surround your code with VBCODE & /VBCODE tags it easier to read your code.
VB Code:
listBox1.Items.Add(userInput)
-
Oct 16th, 2006, 10:31 PM
#7
Re: Need help creating a program
Here it comes
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
Edit** as shown above.
-
Oct 16th, 2006, 10:31 PM
#8
Fanatic Member
Re: Need help creating a program
Jmcilhinney got 3 post in before I got 1 - speed racer!!!
-
Oct 16th, 2006, 10:49 PM
#9
Re: Need help creating a program
Everyone here got a life in before I got any.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|