Qbasicnews.com

Full Version: WHAT IS WRONG WITH THIS SCRIPT?!?!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Could someone please tell me what i'm doin wrong here!!
I type the following script in and then get the message 'Block IF without END IF' and cant run my script

THE SCRIPT:

INPUT "choice", mainmenu%
IF mainmenu% = 1 THEN
GOTO 1
IF mainmenu% = 2 THEN
GOTO 2
IF mainmenu% = 3 THEN
GOTO 3
IF mainmenu% = 4 THEN
GOTO 4
IF mainmenu% = 5 THEN
GOTO 5
IF mainmenu% = 6 THEN
GOTO 6
ELSE
GOTO 7
END IF

PLEASE HELP!!!!!!!!!!
Easily Fixed:

Code:
INPUT "choice", mainmenu%
IF mainmenu% = 1 THEN
GOTO 1
END IF
IF mainmenu% = 2 THEN
GOTO 2
END IF
IF mainmenu% = 3 THEN
GOTO 3
END IF
IF mainmenu% = 4 THEN
GOTO 4
END IF
IF mainmenu% = 5 THEN
GOTO 5
END IF
IF mainmenu% = 6 THEN
GOTO 6
END IF

GOTO 7
Actually It'd be easier with this:

Code:
INPUT " Select number (1-6): ", number%

SELECT CASE number%
CASE "1"
GOTO 1
CASE "2"
GOTO 2
CASE "3"
GOTO 3
CASE "4"
GOTO 4
CASE "5"
GOTO 5
CASE "6"
GOTO 6
END SELECT
(if less typing is "easier"):

INPUT "choice", mainmenu%
IF mainmenu% = 1 THEN GOTO 1
IF mainmenu% = 2 THEN GOTO 2
IF mainmenu% = 3 THEN GOTO 3
IF mainmenu% = 4 THEN GOTO 4
IF mainmenu% = 5 THEN GOTO 5
IF mainmenu% = 6 THEN GOTO 6
GOTO 7
Code:
IF mainmenu% >= 1 THEN IF mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Code:
IF mainmenu% >= 1 AND mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Tongue
I always thought it was quite an oversight not being able to branch directly on a variable value. Like GOTO a% or GOSUB a$

But I'm sure there's a good reason for it.. right Glenn?
I'll tell you why.

When QB compiles, it converts all labels and line numbers to a program address. Doing GOTO a$ is impossible because there wouldn't exist any such thing when running the program. GOTO a%, however, is possible, if you include a range (say 0 to 5):
The compiler would just have to convert
GOTO a%(0 to 5) to:
ON a% GOTO 0, 1, 2, 3, 4, 5 .

But it doesn't.

EDIT: Of course, qb could have a feature that retains each label in strings in some section of the code, and the corresponding converted addresses. It wouldn't take up very much room. That way what you describe is possible and creates a more flexible language. But it doesn't do that.
But if one didn't have to find workarounds for things people wish whatever compiler they're using could do that it can't explicitly do, well, 90% of the fun of programming would be gone. Smile (I'm not sure that 90% of programming, period, wouldn't be gone. Smile )

Quote:I always thought it was quite an oversight not being able to branch directly on a variable value. Like GOTO a% or GOSUB a$

But I'm sure there's a good reason for it.. right Glenn?
Glenn, Glenn! Did you read my post? There is a good reason!
Pages: 1 2 3