I am very interested in direction of program execution , so I would be grateful if anyone with knowledge enough could please help me with my code problem and also if possible expand on what is written in the manual (?)
This code executes correctly for On...Goto without Sub
Code: Select all
Dim choice As String
Dim text As String
DIM p as Integer
DIM x as Integer
Print "Select a Hello"
Print "1. Moon"
Print "2. Stars"
Labelinput:
Do
choice = Input(1)
Loop Until choice >= "1" And choice <= "2"
p = ValInt(choice)
On p goto LabelHello1,LabelHello2
LabelHello1:
text = "A Hello World from the Moon!"
Print text
Goto Labelinput
LabelHello2:
text = "Another Hello to the World from the Stars!"
Print text
Goto Labelinput
SLEEP
Code: Select all
Dim choice As Integer
Dim text As String
Labelinput:
Print
Input "Select 1 for Moon , Select 2 for Stars: "; choice
Select Case As Const choice
Case 1
Goto LabelHello1
Case 2
Goto LabelHello2
Case Else
Print "number is outside the 1-2 range"
End Select
Goto Labelinput
LabelHello1:
text = "A Hello World from the Moon!"
Print text
Goto Labelinput
LabelHello2:
text = "Another Hello to the World from the Stars!"
Print text
Goto Labelinput
SLEEP
So I am looking for code correction help for using both On...Goto and Select Case
Here is the problem code using On...Goto :
Compiler errors :
error 41: Variable not declared, Hello1 in 'Hello1()'
error 41: Variable not declared, Hello2 in 'Hello2()'
Code: Select all
Dim choice As String
DIM p as Integer
DIM x as Integer
Print "Select a Hello"
Print "1. Moon"
Print "2. Stars"
Labelinput:
Do
choice = Input(1)
Loop Until choice >= "1" And choice <= "2"
p = ValInt(choice)
On p goto LabelHello1,LabelHello2
LabelHello1:
Hello1()
LabelHello2:
Hello2()
Sub Hello1()
Dim text As String
text = "A Hello World from the Moon!"
Print text
END SUB
Sub Hello2()
Dim text As String
text = "Another Hello to the World from the Stars!"
Print text
END SUB
SLEEP
error 41: Variable not declared, Hello1 in 'Hello1()'
error 41: Variable not declared, Hello2 in 'Hello2()'
Code: Select all
Dim choice As Integer
Dim text As String
Labelinput:
Print
Input "Select 1 for Moon , Select 2 for Stars: "; choice
Select Case As Const choice
Case 1
Goto LabelHello1
Case 2
Goto LabelHello2
Case Else
Print "number is outside the 1-10 range"
End Select
Goto Labelinput
LabelHello1:
Hello1()
Goto Labelinput
LabelHello2:
Hello2()
Goto Labelinput
Sub Hello1()
Dim text As String
text = "A Hello World from the Moon!"
Print text
END SUB
Sub Hello2()
Dim text As String
text = "Another Hello to the World from the Stars!"
Print text
END SUB
SLEEP
First of all then I have learned that both On...Goto and Select Case can be used to direct using standard labels , but can one direct directly to SUB also ? If so then how to use the sub call (ref. my program errors) ?
Secondly then it says in description in the manual about On....Goto that : "It is recommended that the structured Select Case conditional statement be used instead of On...Goto."
Why is that recommended ? are the On....Goto going to be phased out ? / will it be unsupported in the future ?
I am sorry if asking too many questions . Anyway help with getting the code to run is the top priority if anyone will be so kind as to assist me that is :-)