Posts: 358
Threads: 15
Joined: May 2003
Quote: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 6
ELSE
GOTO 7
END IF
PLEASE HELP!!!!!!!!!!
The following is how block if then is structured...note the ELSE IF...your original code had 7 nested block if then statements...you needed 7 END IF statements to make it work...
INPUT "choice", variable
IF variable = 1 THEN
do this stuff
ELSE IF variable = 2 THEN
do this stuff
ELSE
do this
END IF
read the manual is good advice...and look at other people's code...and experiment...
Posts: 2,765
Threads: 138
Joined: Nov 2002
Quote:Code:
IF mainmenu% >= 1 THEN IF mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Dude... You saved me some room in the program i was working on! Thanx! :o
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 354
Threads: 11
Joined: May 2002
Quote:Agamemnus Wrote:Code:
IF mainmenu% >= 1 THEN IF mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Dude... You saved me some room in the program i was working on! Thanx! :o
You'll save even more room if you change that THEN IF to an AND
In a world without walls and doors, who needs Windows and Gates?
Posts: 1,813
Threads: 284
Joined: Mar 2003
I was thinking the same thing Piptol but before I could post that, I came across Rel's post from a long while ago:
Quote:Seph:
Slow:
Code:
if X=0 and Y=1 and Z=3 then
End if
Faster: (They call this "Short Circuit"
Code:
If X=0 then
if Y=1 then
if Z=3 then
End if
End if
End if
earn.
Posts: 354
Threads: 11
Joined: May 2002
Hmm, guess I should have known that from C++. For some reason though I didn't think it worked like that in QB. Oh well, I bow to rel's genius (on this occassion, at least)
In a world without walls and doors, who needs Windows and Gates?
Posts: 3,368
Threads: 195
Joined: Jan 2003
And it only takes a few lines of code to convert from a AND b to IF THEN b.
Pitiful.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 2,765
Threads: 138
Joined: Nov 2002
so ut's faster to do it the Short Circuit way?
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 3,368
Threads: 195
Joined: Jan 2003
As I remember someone else saying, QB first reads the WHOLE IF part of the statement then evaluates the WHOLE statement instead of reordering any parentheses and evaluating it incrementally.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 199
Threads: 2
Joined: May 2003
Quote:whitetiger0990 Wrote:Agamemnus Wrote:Code:
IF mainmenu% >= 1 THEN IF mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Dude... You saved me some room in the program i was working on! Thanx! :o
You'll save even more room if you change that THEN IF to an AND
Quote:Code:
IF mainmenu% >= 1 AND mainmenu% <= 6 THEN ON mainmenu% GOTO 1, 2, 3, 4, 5, 6
Obviously didn't see my earlier post then :/
url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79]
[/url]
END OF LINE
.
Posts: 2,765
Threads: 138
Joined: Nov 2002
I am still confused. So if you use:
Code:
IF a = 1 AND b = 1 THEN c = 1
it is faster then
Code:
IF a = 1 THEN IF b = 1 THEN c = 1
:???:
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.