Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repetitive Do While loop

Status
Not open for further replies.

BobtheRookie

Programmer
May 19, 2002
1
US
First i have this code written

StrAge = InputBox("How old are you?", "Age ask")
If (StrAge = "") Then
End
End If

IntAge = Val(StrAge)

Do While ((IntAge < 10) Or (IntAge > 99))
IntPress = MsgBox(&quot;your age must be between 10 and 99&quot;, vbExclamation, &quot;Error!&quot;)
StrAge = InputBox(&quot;How old are you?&quot;, &quot;Age ask&quot;)

If (StrAge = &quot;&quot;) Then
End
End If

IntAge = Val(StrAge)
Loop

when i run this program i put in a number greater than 99. this tells me that i have to have a number between 10 and 99. After the input screen comes up again i put in a valid number and press enter. After i press enter the input box comes up again asking for my age but goes away after the second time i put it in.

What is wrong with my code and why does it repeat itself?
 
Hi,

I have Visual Basic 6 at home and tested your code and it worked fine. Are you using Visual Basic 5 or 6? Also, have you declared the variables earlier in the code? If you have, you may check to see if it is correct. Finally, you may check the rest of your program to see if you accidently used the variable names elsewhere. If all of this does not work, I would insert a breakpoint at the Loop statement (you can do this by pressing F9). Once the computer has paused your program, you can move your cursor to the name of a variable and it will tell you its value. This may offer you some insight. I hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top