|
-
May 1st, 2008, 05:48 AM
#1
Thread Starter
Addicted Member
[RESOLVED] A little help with Inputbox and MsgBox
My code is like this
just for example only:
vb Code:
strRightAnswer = "2"
strAnswer = InputBox("1+1 = ?", "")
If strAnswer = strRightAnswer Then
MsgBox "Your Answer is Correct!", vbInformation
ElseIf Trim(strAnswer) = "" Then
MsgBox "You don't have an answer!", vbInformation
Else
MsgBox "Your Answer is Wrong!", vbInformation
End If
If Trim(strAnswer) = "" Then
z = MsgBox("Are You Sure you want to skip this question?", vbInformation + vbOKCancel, "")
End If
The code works fine I think, but I need a help.
When the user types an answer to the text field, it will be stored in the strAnswer variable?
So when the user didn't type any answer or presses the cancel button in the InputBox in the Statement Line 2, it to go directly to the Statement Line 11 and Line 12
I need a little help in there, so that when the user click the cancel button, it will then re-prompt again the same question.
Help! Thanks!
-
May 1st, 2008, 05:55 AM
#2
Re: A little help with Inputbox and MsgBox
Check this out
Code:
Private Sub Command1_Click()
If Question = 2 Then
Question
End If
End Sub
Public Function Question() As Integer
strRightAnswer = "2"
strAnswer = InputBox("1+1 = ?", "")
If strAnswer = strRightAnswer Then
MsgBox "Your Answer is Correct!", vbInformation
ElseIf Trim(strAnswer) = "" Then
MsgBox "You don't have an answer!", vbInformation
Else
MsgBox "Your Answer is Wrong!", vbInformation
End If
If Trim(strAnswer) = "" Then
z = MsgBox("Are You Sure you want to skip this question?", vbInformation + vbOKCancel, "")
Question = z
End If
End Function
-
May 1st, 2008, 08:03 PM
#3
Thread Starter
Addicted Member
Re: A little help with Inputbox and MsgBox
Thanks Sir! But I have a question, the statement:
vb Code:
If Question = 2 Then Question End If
Why "= 2" ?
Does the number corresponds to the Cancel Button?
Thanks Anyway! ^_^
Last edited by belvita; May 1st, 2008 at 08:10 PM.
-
May 2nd, 2008, 04:22 AM
#4
Re: A little help with Inputbox and MsgBox
 Originally Posted by belvita
Thanks Sir! But I have a question, the statement:
vb Code:
If Question = 2 Then
Question
End If
Why "= 2" ?
Does the number corresponds to the Cancel Button?
Thanks Anyway! ^_^
I'm not your SIR.......
Yes 2 corresponds to Cancel and 1 to Ok.When an user hits cancel msgbox will return 2 , if ok it will return 1...
-
May 2nd, 2008, 04:30 AM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] A little help with Inputbox and MsgBox
Oh I'm sorry. But anyway, 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
|