Tutorial - Error Message?

Discussion in 'Questions (Windows Mobile)' started by ArchiMark, Sep 18, 2007.

  1. ArchiMark

    ArchiMark Member Licensed User

    As Erel suggested, I'm posting the code I typed in for the new tutorial as I get an error message regarding:


    This refers to this section of code near the end:
    Code:
    Else
                 AppClose
          
    End If
    End If
    Maybe I just need to get new eyeglasses, but I don't see what's wrong?

    Thanks,

    Mark


    Code:
    Sub Globals
       
    'Declare the global variables here.
       Dim Number

    End Sub

    Sub App_Start
       Form1.Show
       Number = 
    Rnd(1,100)'Randomly chooses a number
    End Sub


    Sub btnGuess1_Click
       
    If Not (IsNumber(txtNumber1.Text))Then 'User didn't enter valid number
       'Same as If Not (IsNumber(txtNumber1.Text)= False Then
       
          
    Msgbox ("Please enter a valid number")
       
    Return 
    End If

    If txtNumber1.Text > number Then 'Check the user guess
       Msgbox ("My number is smaller")
       
    Else If txtNumber1.Text < number Then 
       
    Msgbox ("My number is larger")
       
    Else 'The user has found the right number
       Msgbox ("Congrats, you've found the right number!"crlf & "Do you want to play a new game?""", cMsgbox YesNo) = cYes Then
       number = 
    Rnd (1,100)
       
    Else
          AppClose
       
    End If
    End If

    txtNumber1.focus 
    'Returns focus to textbox & selects text
    txtNumber1.SelectionStart = 0
    txtNumber1.SelectionLength = StrLength (txtNumber1.Text)
    End Sub
     
  2. petrbury

    petrbury Member Licensed User

    Hi,
    there is missing command "IF" in line :
    IF Msgbox ("Congrats, you've found the right ...
    So you have more End IF then IF commands and it takes an Error message.
    I recomend you to give IF ELSE and END IF commands on the same TAB position (as you can see in Erel's example), so your code will be more synoptical.
    Petr
     
  3. willisgt

    willisgt Active Member Licensed User

    Code Fix

    Archimark -

    Change the line

    to

    That'll get it.

    Gary
     
  4. ArchiMark

    ArchiMark Member Licensed User

    THANKS for your help, petrbury & willisgt. Really appreciate it!!!

    The good news is that the error message went away!!

    The bad news is that now when I run the app and I enter the right number I get the following error message:

    Code:
    An error occurred on sub btnguess_click.

    line number: 
    28

    If Msgbox ("Congrats, you've found the right number!" & crlf & "Do you want to play a new game?"" ", cMsgbox YesNo) = cYes Then

    Error Description:

    Variable: cmsgbox was 
    not assigned any value.

    Continue?
    Then it gives you a 'Yes' or 'No' button to choose from....

    :confused:
     
  5. specci48

    specci48 Well-Known Member Licensed User

    Hi ArchiMark,

    there must be no space between "cMsgbox" and "YesNo" since only "cMsgboxYesNo" is a vaild basic4ppc messagebox constant.
    So change
    Code:
    If Msgbox ("Congrats, you've found the right number!" & crlf & "Do you want to play a new game?"" ", cMsgbox YesNo) = cYes Then
    to
    Code:
    If Msgbox ("Congrats, you've found the right number!" & crlf & "Do you want to play a new game?"" ", cMsgboxYesNo) = cYes Then
    and the tutorial should work as expected...

    specci48
     
  6. ArchiMark

    ArchiMark Member Licensed User


    That did it, specci48. THANKS for your help!
     
Loading...