Tutorial - Error Message?

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:

Missing Keyword: End Sub
Occurred on line: 33
End If


This refers to this section of code near the end:
B4X:
Else
             AppClose
      End If
End If

Maybe I just need to get new eyeglasses, but I don't see what's wrong?

Thanks,

Mark


B4X:
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
 

petrbury

Member
Licensed User
Longtime 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
 

willisgt

Active Member
Licensed User
Code Fix

Archimark -

Change the line

Msgbox ("Congrats, you've found the right number!"...

to

If Msgbox ("Congrats, you've found the right number!"...

That'll get it.

Gary
 

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:

B4X:
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:
 

specci48

Well-Known Member
Licensed User
Longtime User
Hi ArchiMark,

there must be no space between "cMsgbox" and "YesNo" since only "cMsgboxYesNo" is a vaild basic4ppc messagebox constant.
So change
B4X:
If Msgbox ("Congrats, you've found the right number!" & crlf & "Do you want to play a new game?", " ", cMsgbox YesNo) = cYes Then
to
B4X:
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
 

ArchiMark

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
B4X:
If Msgbox ("Congrats, you've found the right number!" & crlf & "Do you want to play a new game?", " ", cMsgbox YesNo) = cYes Then
to
B4X:
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


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