Results 1 to 5 of 5

Thread: [RESOLVED] A little help with Inputbox and MsgBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Resolved [RESOLVED] A little help with Inputbox and MsgBox

    My code is like this

    just for example only:
    vb Code:
    1. strRightAnswer = "2"
    2. strAnswer = InputBox("1+1 = ?", "")
    3. If strAnswer = strRightAnswer Then
    4. MsgBox "Your Answer is Correct!", vbInformation
    5. ElseIf Trim(strAnswer) = "" Then
    6. MsgBox "You don't have an answer!", vbInformation
    7. Else
    8. MsgBox "Your Answer is Wrong!", vbInformation
    9. End If
    10.  
    11. If Trim(strAnswer) = "" Then
    12. z = MsgBox("Are You Sure you want to skip this question?", vbInformation + vbOKCancel, "")
    13. 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!

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Smile 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    Re: A little help with Inputbox and MsgBox

    Thanks Sir! But I have a question, the statement:

    vb Code:
    1. If Question = 2 Then
    2.         Question
    3.    
    4. 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.

  4. #4
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Smile Re: A little help with Inputbox and MsgBox

    Quote Originally Posted by belvita
    Thanks Sir! But I have a question, the statement:

    vb Code:
    1. If Question = 2 Then
    2.         Question
    3.    
    4. 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...

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Location
    Philippines
    Posts
    246

    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
  •  



Click Here to Expand Forum to Full Width