parsing concatenated statements

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Post Reply
gremlin4
Newbie
Posts: 9
Joined: Sun Jun 29, 2014 9:16 am

parsing concatenated statements

Post by gremlin4 »

Now aged 80, have taken up my interest in programming in Basic again, after a lapse of about 10 years, so I'm a bit rusty.
I have been trying to figure out the method by which a SuDoKuSolver I found on the internet works. Now, I am used to 'IF constructs with multiple statements following the THEN being terminated by an ENDIF.
It's not so with this snippet:-
IF i$ = " " then gr$(x, y) = " ": GOSUB ff: .........
My question is, is the GOSUB only to be carried out if the IF is true, or anyway.?

Edit:..the 'then' should of course have been 'THEN' and there was no 'ENDIF' to be found.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: parsing concatenated statements

Post by burger2227 »

When the space bar is pressed, X$ = "A" and the GOSUB is executed

Code: Select all

DO: i$ = INKEY$: LOOP UNTIL LEN(i$)

IF i$ = " " THEN x$ = "A": GOSUB ff:
PRINT i$, x$

END 'must use END/SYSTEM or the GOSUB will run before ending the program with a RETURN without GOSUB error.

ff:
PRINT "Space bar pressed"
RETURN
A single line IF statement does not require END IF as it is not a statement block that needs a defined end.

Everything after THEN will be executed when the statement is TRUE
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
gremlin4
Newbie
Posts: 9
Joined: Sun Jun 29, 2014 9:16 am

Re: parsing concatenated statements

Post by gremlin4 »

hello again burger 2227

I just spent an hour preparing a reply, had to go to the loo, when I came back, all my work had vanished
Some of the text giving me nightmares is this

cc:
'locate to 11, 19 , (WHY?) then get icon PRINTING THE ICON HERE IS NEEDED!
LOCATE (y * 2) + 1, (x * 4) - 1: COLOR 11: i$ = CHR$(2): PRINT i$ ‘print i$ is my addition

'at this stage, fl = 0 (yes, I checked this)
'and gr$(x, y) IS " ", (len(gr$(x, y)) checks as 1), but perhaps its just s spsce
‘ so 'IF' fails!. PUT ICON – but it doesn’t show up
IF fl = 0 AND gr$(x, y) <> " " THEN i$ = gr$(x, y): 'Print i$ = wrong

compare with the original, all being well it will be tagged on below.

as its now 4 am I quit for now
Ed
gremlin4
Newbie
Posts: 9
Joined: Sun Jun 29, 2014 9:16 am

Re: parsing concatenated statements

Post by gremlin4 »

hello again, again,burger 2227

I must admit to having been stupid. The answer to my problem was staring at me.
I had split the statement(s)

IF fl = 0 AND gr$(x, y) = " " THEN i$ = gr$(x, y) :PRINT i$

into

IF fl = 0 AND gr$(x, y) = " " THEN i$ = gr$(x, y) :
PRINT i$

whereas I should have typed

IF fl = 0 AND gr$(x, y) = " " THEN i$ = gr$(x, y)
PRINT i$

Thats it!

Sorry, that's not QUITE right. If the PRINT i$ on the same line as the IF, i will be controlled by it.
Thats not what is needed. The Print i$ must be on a new line. The colon is neither here nor there
I'll shut up now. Thanks for your support
Bye, Ed
Post Reply