1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Inputbox

Discussion in 'Visual Basic ( VB )' started by stuka, Apr 26, 2009.

  1. stuka

    stuka New Member

    ok im having trouble with my imput box it crashes when i enter text, nothin and when i press the cancel button. i do realise when i click the cancel buttin it returns a null value and vb doesnt like it but why does it crash with letters or typing nothin because i have put if it = "" then.... shouldnt that mean it will accept nothin entered?

    heres one of the input boxes maybe u can tell what im doin wrong and how to fix it.

    Code:
    If question1 = 1 And level = 0 And x >= 134 And x < 275 Then
                Form1.txtlevel.Text = 1
                x = 134
                aboard.Draw(g)
                Me.Draw(g)
    
                Dim Q As String
                Dim number1 As Short
                Dim number2 As Short
                Dim result As Short
    
                number1 = Int((100 * Rnd()) + 1)
                number2 = Int((100 * Rnd()) + 1)
                Q = InputBox("what is " & number1 & " + " & number2 & " ?")
                Randomize()
    
                result = number1 + number2
                If Q = result Then
                    MsgBox("You got it right!")
                    question1 = 2
                    Form1.Txtquestion1.Text = 2
    
                ElseIf Q = "" Then
                    Form1.Txtlives.Text = Form1.Txtlives.Text - 1
                    MsgBox("Correct answer is: " & result & ", Your going back!")
                    MsgBox("you Lost of life you have " & Form1.Txtlives.Text & " left")
                    x = 134 - 120
                    aboard.Draw(g)
                    Me.Draw(g)
    
                Else
                    Form1.Txtlives.Text = Form1.Txtlives.Text - 1
                    MsgBox("Correct answer is: " & result & ", Your going back!")
                    MsgBox("you Lost of life you have " & Form1.Txtlives.Text & " left")
                    x = 134 - 120
                    aboard.Draw(g)
                    Me.Draw(g)
               End if
     
  2. nimesh

    nimesh New Member

    The code looks clean to me and according to me it works if you write
    If Q = ""
    Did you try debugging?
    Does it crash at this statement?

    You can try using vbNull or just NULL, whichever works correctly.
    ElseIf Q = vbNull Then
    or
    ElseIf Q = Null Then

    Let me know the outcome.

    - Nimesh
     
    shabbir likes this.
  3. stuka

    stuka New Member

    i got a reply on another forum and that way seems to have worked perfect plus made the code alot shorter but thanks for your reply :)
     

Share This Page