|
-
Feb 26th, 2007, 03:15 AM
#1
Thread Starter
Addicted Member
[RESOLVED][2005] Simple loop question
I have a simple loop question. I have played with this for sometime but I seem to not be able to get my desired output. I just want a simple loop that runs until the counter = 10 and stores the variable result in a listbox. The problem I am having is that I can not seem to get the loop to stop taking information. Can someone give me a hand as to how to make this loop stop?
VB Code:
Dim intCount as Integer = 1
Dim intInput as Integer
InInput = CInt(InputBox("Please enter a number to be stored",,CStr(1)))
Do Until intCount = 10
intcount += 1
Loop
lstNumbers.Items.Add(intInput)
Now why is it this loop continues to accept information after the counter reaches 10? Is it because its a prompted response from the user or am I leaving out some form of input validation?
As always I have searched but the problems that I search on this board are from people that are usually devs with real world problems. I'm just trying to understand the fundamentals at this point Let me know what you guys think.
Abe
Asking the beginners questions so you don't have to.
Last edited by Abrium; Feb 26th, 2007 at 05:56 AM.
Reason: Resolved
-
Feb 26th, 2007, 03:52 AM
#2
Hyperactive Member
Re: [2005] Simple loop question
You can use a number of other loops that will do the job
VB Code:
Dim intCount as Integer = 1
Dim intInput as Integer
InInput = CInt(InputBox("Please enter a number to be stored",,CStr(1)))
For intCount to 10
intCount += 1
next intcount
lstNumbers.Items.Add(intInput)
or you can do this
VB Code:
While not intcount <> 10
intcount += 1
end while
HTH
-
Feb 26th, 2007, 03:55 AM
#3
Frenzied Member
Re: [2005] Simple loop question
Is the code you posted your actual code?
If so, you have a typo.
Dim intInput as Integer
InInput = CInt(InputBox("Please enter a number to be stored",,CStr(1)))
Typo on your variable intInput
I'm not sure if that is your problem or not
-
Feb 26th, 2007, 04:05 AM
#4
Re: [2005] Simple loop question
That loop has nothing to do with accepting information. You call InputBox outside the loop so it's only executed once no matter what. If you want an action performed multiple times it has to be inside the loop. The only thing you're doing inside the loop is incrementing intCount. That loop will complete in about a millisecond.
-
Feb 26th, 2007, 04:20 AM
#5
Thread Starter
Addicted Member
Re: [2005] Simple loop question
What I am wanting this loop to do is stop prompting me for the input once the intCount = 10. And that was a typo on my part in the code its correct. So how would I alter this code to ensre that the input box stops prompting me once my intCount reaches 10. As with everytime I post I could of just been starting at this too long. For me this is advanced code and the text does explain it well but it doesn't offer reasoning if you can't understand a certain part of the code or why it works.
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
-
Feb 26th, 2007, 04:33 AM
#6
Re: [2005] Simple loop question
Like I said, put the InputBox inside the loop. Also, if you're expecting that all ten input values will end up in the ListBox then you'll have to move that last line inside the loop too. The loop contents get executed multiple times, therefore whatever you want executed multiple times must be inside the loop.
-
Feb 26th, 2007, 05:54 AM
#7
Thread Starter
Addicted Member
Re: [2005] Simple loop question
Abrium
Asking the beginners questions so you don't have to!
If by chance hell actually froze over and I some how helped you... Please rate.
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
|