|
-
Jan 30th, 2007, 05:33 PM
#1
Thread Starter
Member
[RESOLVED] What is wrong with this code?
VB Code:
strinput = InputBox("Who are you?")
For i = 0 To 2
If guest(i) = strinput Then
blnvalid = True
Else: blnvalid = False
End If
Do While blnvalid = False
strinput = ("reenter")
Loop
Next i
I'm trying to validate an input and if validation = false, a new question will be asked instead of the thing looping the same question.
-
Jan 30th, 2007, 05:38 PM
#2
Hyperactive Member
Re: What is wrong with this code?
What type of error are you getting????????
When I put in your code onto a simple program, the program gets stuck in the Do Loop structure...
Why is the Do Loop there anyways... ???
Please be more precise!!!
Hey... If you found this post helpful please rate it.

-
Jan 30th, 2007, 05:41 PM
#3
Thread Starter
Member
Re: What is wrong with this code?
The code won't run at all in my program, probably because some errors in my other part of program.
For the do..loop... i'm trying to get the program to loop a different question if blnvalid = false but stops the loop if blnvalid is found to be true again.
guest is an array of names...
-
Jan 30th, 2007, 05:44 PM
#4
Re: What is wrong with this code?
VB Code:
strinput = InputBox("Who are you?")
For i = 0 To 2
If guest(i) = strinput Then Exit For
Next i
If i = 3 Then ' no match was found
' Ask new question
End if
What might the new question be? (This code is not complete)
-
Jan 30th, 2007, 05:46 PM
#5
Thread Starter
Member
Re: What is wrong with this code?
new question is strinput = ("reenter")
Anyway, here is my original, perectly working code, but it loops the same question when blnvalid = false but I want it to ask a different one and validate it once more.
VB Code:
Do
strinput = InputBox("Who are you?")
'Check if the name is in the array
For i = 0 To 2
If guest(i) = strinput Then
blnvalid = True
End If
Next i
'Loop while a valid name has not been entered
Loop While Not blnvalid
-
Jan 30th, 2007, 05:54 PM
#6
Hyperactive Member
Re: What is wrong with this code?
Are you trying to say that you are getting the same question.... If so then where are you getting your questions from???
Hey... If you found this post helpful please rate it.

-
Jan 30th, 2007, 05:58 PM
#7
Thread Starter
Member
Re: What is wrong with this code?
The question is from here:
strinput = InputBox("Who are you?")
When it first validates, if the blnvalid = true, then it just carry on with other things, however if blnvalid = false, it just loops to the start at the same question.
What i want it to do is to loop when blnvalid = false, but with different question.
Like this: strinput = Inputbox("reenter") when blnvalid = false, this will loop over and over until blnvalid = true
-
Jan 30th, 2007, 06:00 PM
#8
Re: What is wrong with this code?
I wouldn't say that code works perfectly. There is no way to exit the loop except by entering a valid string. Anyway, try this:
VB Code:
Do
strinput = InputBox("Who are you?")
'Check if the name is in the array
For i = 0 To UBound(guest) ' In case you change guest to have more names
If guest(i) = strinput Then Exit For
Next i
If i > UBound(guest) Then
blnvalid = False
answer = MsgBox("No match found. Try again?", vbYesNo)
Else
blnvalid = True
End If
' Loop as long as user wants to try again
' Note that the loop may be exited without a valid input
Loop While answer = vbYes
-
Jan 30th, 2007, 06:09 PM
#9
Thread Starter
Member
Re: What is wrong with this code?
That works perfectly except one little small thing...
when I click "No" for the loop, it doesn't actually quit the program but just move on to the next part of it, which i do no want...
-
Jan 30th, 2007, 06:13 PM
#10
Hyperactive Member
Re: What is wrong with this code?
VB Code:
If answer = "7" Then
MsgBox "No"
End If
Hey... If you found this post helpful please rate it.

-
Jan 30th, 2007, 06:17 PM
#11
Thread Starter
Member
Re: What is wrong with this code?
After a little tinkering, manages to solve it.
Thanks everyone.
-
Jan 30th, 2007, 06:41 PM
#12
Re: What is wrong with this code?
 Originally Posted by vert
That works perfectly except one little small thing...
when I click "No" for the loop, it doesn't actually quit the program but just move on to the next part of it, which i do no want...
That might not be what you want, but it is what you need. After exiting the loop, check the value of blnvalid, then continue accordingly.
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
|