what seems like a bogus syntax error

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
rjoslin414
Newbie
Posts: 5
Joined: Fri Dec 21, 2018 3:31 pm

what seems like a bogus syntax error

Post by rjoslin414 » Fri Dec 21, 2018 4:25 pm

Had extensive experience using QB45 to make .exe programs for older windows versions, but then they wouldn't work any more. Was happy to find QB64. However, I loaded an old gw-basic program into 64 (one that runs fine under DOSBOX/win7) and I get a syntax error in a certain line. The line was a bit complicated and the error message gave no more specific suggestion as to what was wrong. So I broke it up into two lines, the part that gives a syntax error is simply "print#1,xa$" where xa$ was defined in the line immediately before the offending line and gives no error message. file 1 was opened for output a line or two above these lines. I just don't understand what could be wrong syntactically with a print# command followed by a comma and then a valid string. What am I missing here?

PS I wrote a small program using QB64 which compiled just fine and produced an exe file which worked on both win7 and 10, so I don't think there's anything wrong with the version of 64 that I'm using.

Rick Joslin
Carolina Beach, NC

rjoslin414
Newbie
Posts: 5
Joined: Fri Dec 21, 2018 3:31 pm

Re: what seems like a bogus syntax error

Post by rjoslin414 » Mon Dec 24, 2018 3:43 pm

I am updating my post with the code below. It is line 547 that keeps showing a syntax error and QB64 refuses to even start compiling because of it. I can't find anything wrong with it. Plus the two other Print#1 commands at lines 560 and 565 aren't flagged (maybe it stops with the first syntax error and won't go any further.) Can somebody give me an idea about what's going on here?

1 REM mkyr002.bas makeyear v2
2 'to make an entire year's journal files
4 KEY 4, "save" + CHR$(34) + "mkyr002" + CHR$(34) + ",a"
50 DIM MONTH$(12), DAY$(7), NUMDAYS(12), FILNUM$(12)
99 REM DATA LINES
100 DATA January,February,March,April,May,June,July,August,September,October,November,December
110 DATA Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
120 DATA 31,28,31,30,31,30,31,31,30,31,30,31
130 DATA 01,02,03,04,05,06,07,08,09,10,11,12
199 REM load arrays
200 RESTORE 100: FOR Q = 1 TO 12: READ MONTH$(Q): NEXT: PRINT "months loaded"
210 RESTORE 110: FOR Q = 1 TO 7: READ DAY$(Q): NEXT: PRINT "day names loaded"
220 RESTORE 120: FOR Q = 1 TO 12: READ NUMDAYS(Q): NEXT: PRINT "number of days per month loaded"
230 RESTORE 130: FOR Q = 1 TO 12: READ FILNUM$(Q): NEXT
300 REM input year from user
310 REM
320 PRINT "Enter year or 'x' to EXIT": INPUT X$: IF X$ = "" THEN 320
330 IF X$ = "x" THEN END
335 REM handle leap year
340 YEAR = VAL(X$): IF YEAR < 2000 THEN PRINT "Invalid year": GOTO 320
350 LEAP = YEAR MOD 4: IF LEAP = 0 THEN NUMDAYS(2) = 29
400 REM enter starting day of year (1=Sunday)
410 PRINT "ENTER STARTING DAY OF THE WEEK FOR "; YEAR
420 INPUT SD$: SD = VAL(SD$)
430 MONTHCOUNTER = 0
499 YEAR$ = X$
500 REM start the actual output to files
505 REM
510 MONTHCOUNTER = MONTHCOUNTER + 1: REM increment moco to start
515 IF MONTHCOUNTER = 13 THEN END
519 A$ = FILNUM$(MONTHCOUNTER)
520 OPEN "o", 1, A$ + LEFT$(MONTH$(MONTHCOUNTER), 3) + MID$(STR$(YEAR), 4, 2) + ".txt"
530 FOR Q = 1 TO NUMDAYS(MONTHCOUNTER)

546 xa$ = MONTH$(MONTHCOUNTER) + STR$(Q) + ", " + years$

547 PRINT#1,xa$
550 REM day of week part
560 PRINT#1,DAY$(SD): SD=SD+1: IF SD=8 THEN SD=1
565 PRINT#1,
570 NEXT: CLOSE 1
600 IF MONTHCOUNTER=13 THEN END
610 GOTO 500

User avatar
burger2227
Veteran
Posts: 2271
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: what seems like a bogus syntax error

Post by burger2227 » Mon Dec 24, 2018 10:48 pm

Try running the code example on the page below:

https://www.qb64.org/wiki/PRINT_(file_statement)
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

rjoslin414
Newbie
Posts: 5
Joined: Fri Dec 21, 2018 3:31 pm

Re: what seems like a bogus syntax error

Post by rjoslin414 » Sat Dec 29, 2018 6:57 am

Thanks for your help. I've typed two much longer replies and keep getting booted off without saving the post.

rjoslin414
Newbie
Posts: 5
Joined: Fri Dec 21, 2018 3:31 pm

Re: what seems like a bogus syntax error

Post by rjoslin414 » Sat Dec 29, 2018 6:58 am

Fourth time is the charm, I guess. My lesson learned is that there must be a space between PRINT and #

rjoslin414
Newbie
Posts: 5
Joined: Fri Dec 21, 2018 3:31 pm

Re: what seems like a bogus syntax error

Post by rjoslin414 » Mon Dec 31, 2018 7:04 am

More on the above problem:
Now that I've gotten the "space between PRINT and #" rule in my head
I get an "Expected operator in equation" error in this line

xa$=month$(monthcounter)+str$(q)+", "year$

I couldn't figure out anything wrong with this line of code at all, and as before, it runs just fine and generates no error in GWBASIC running under DOSBOX... BUT when I kept thinking about the error message, I finally figured out that an additional "+" sign was needed between "," and year$.

I present this only to help others who might have the same problem.

Wouldn't it be great if QB64 could highlight where an error occurred in orange? Unless you are the actual author of QB64, you can't add this enhancement yourself, but maybe the powers that be will see this suggestion (or maybe it's old and can't be fixed).

Happy New Year!

PS I keep having to log back on to submit my posts, so this may never make it to the board.

User avatar
burger2227
Veteran
Posts: 2271
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: what seems like a bogus syntax error

Post by burger2227 » Mon Dec 31, 2018 8:18 am

When you sign into the board, check the stay logged in box.
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

Post Reply