[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!
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
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! ^_^
Re: A little help with Inputbox and MsgBox
Quote:
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...
Re: [RESOLVED] A little help with Inputbox and MsgBox
Oh I'm sorry. But anyway, thanks! ^_^