|
-
Oct 17th, 2006, 01:31 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Repeating msgbox...
Hello everybody,
I have a question (vb 2005).
I have an inputbox that askes the user a question.
If the user types in the right anwser a label appears with the text "good job!".
If the user anwsers the wrong anwser than a label appears with the text "Wrong!".
Here comes my problem.
If the user types in nothing ("") I want a msgbox to appear that tells the user that he has to insert an anwser.
After the user clicks ok on the msgbox, again the inputbox appears.
Again if the user types nothing the msgbox appears, etc, etc,,,
Can anybody help my figure out the structure of this problem.
So far I got the followong code:
if inputbox = "Good Anwser" then
label.text = "Great!"
elseif inputbox = "Wrong Anwser" then
label.text = "Wrong!"
else inputbox = "" then
msgbox("you must type in an anwser")
(how can I return to the point that the inputbox appears???)
end if
Thanks very much in advance for your help guys...
-
Oct 17th, 2006, 01:42 AM
#2
Re: Repeating msgbox...
Display your InputBox and get the return value into a variable. Then use a While loop to test that value and, if it is an empty string, display your MessageBox and then another InputBox. If the user enters a value then the loop will never be entered. If the loop is entered then it wil be exited as soon as the user enters a value. After the loop you can test that value returned to see if it is the correct answer or not. Note that this requires InputBox to be used exactly twice in your code. Not once and not more than twice.
-
Oct 17th, 2006, 01:50 AM
#3
Hyperactive Member
Re: Repeating msgbox...
Hi,
You can do the same that jmc told you and just using one inputbox; instead on the WHILE loop you can use a DO loop, put the inputbox line inside your loop, asing the result to a variable and check at the end of the loop
VB Code:
do
'put here your inputbox
loop while 'check your var to the correct value in order to exit the loop
hope this helps
-
Oct 17th, 2006, 02:26 AM
#4
Re: Repeating msgbox...
 Originally Posted by josep
Hi,
You can do the same that jmc told you and just using one inputbox; instead on the WHILE loop you can use a DO loop, put the inputbox line inside your loop, asing the result to a variable and check at the end of the loop
VB Code:
do
'put here your inputbox
loop while 'check your var to the correct value in order to exit the loop
hope this helps
And how exactly will the MessageBox be shown if and only if the user enters a blank value?
-
Oct 17th, 2006, 02:54 AM
#5
Hyperactive Member
Re: Repeating msgbox...
Just like that
VB Code:
Do
i = InputBox("pp")
If i = "" Then MsgBox("blank answer")
Loop While i = "" Or (i <> "g" And i <> "w")
forgot to tell on my previous post just checking the blank answer for msgbox display
-
Oct 17th, 2006, 03:17 AM
#6
Re: Repeating msgbox...
That'll do it. I guess I was assuming only testing the return value once, but there is really nothing to stop you testing it twice.
VB Code:
Dim answer As String = InputBox("Prompt")
While answer = String.Empty
MessageBox.Show("Message")
answer = InputBox("Prompt")
End While
-
Oct 17th, 2006, 08:26 AM
#7
Thread Starter
Fanatic Member
Re: Repeating msgbox...
Thank you very much guys.
your anwser helped great.
Thanks!!!
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
|