Author Topic: Odd Data/Read syntax error  (Read 4223 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Odd Data/Read syntax error
« on: November 30, 2019, 11:12:59 am »
The following syntax error is not making sense

Data Snippet (saved as gamedata.bi)

Code: QB64: [Select]
  1. STAR_NAMES:
  2. DATA "Lelande 21185","NI,P"
  3. DATA "Alpha Centauri","NA,I"
  4. DATA "Sirius","A"
  5. DATA "Benards Star","I,P"
  6. DATA "Sol","R"
  7. DATA "Ross 154","NI,NA"
  8. DATA "Episilon Eridani","A,P"
  9. DATA "Luyten 726-8","NA"
  10. DATA "Luyten 789-6","A,NI,P"
  11. DATA "Ross 248","A,I"
  12.  

Main code to read this:
Code: QB64: [Select]
  1.     DIM A, B AS STRING
  2.     DIM I AS INTEGER
  3.  
  4.     FOR I = 1 TO 10
  5.         READ A, B '<--- SYNTAX ERROR
  6.         PRINT A
  7.         PRINT B
  8.         END
  9.  
  10.         PRINT USING "##"; I;
  11.         PRINT TAB(5); A; TAB(21); B;
  12.         PRINT TAB(29);: PRINT USING "##.##"; DD(I);
  13.         PRINT TAB(35);: PRINT USING "####"; T(I)
  14.     NEXT
  15.  
Odd thing, if I press YES to continue through the error it displays correctly??!!?

Thanks!
EDIT: Added how the variables are DIM'd
« Last Edit: November 30, 2019, 11:26:35 am by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Odd Data/Read syntax error
« Reply #1 on: November 30, 2019, 11:23:00 am »
Is A and B both defined as STRINGs?

Code: QB64: [Select]
  1. STAR_NAMES:
  2. DATA "Lelande 21185","NI,P"
  3. DATA "Alpha Centauri","NA,I"
  4. DATA "Sirius","A"
  5. DATA "Benards Star","I,P"
  6. DATA "Sol","R"
  7. DATA "Ross 154","NI,NA"
  8. DATA "Episilon Eridani","A,P"
  9. DATA "Luyten 726-8","NA"
  10. DATA "Luyten 789-6","A,NI,P"
  11. DATA "Ross 248","A,I"
  12.  
  13.  
  14.  
  15. FOR I = 1 TO 10
  16.     READ A, B '<--- SYNTAX ERROR
  17.  
  18.     PRINT USING "##"; I;
  19.     PRINT TAB(5); A; TAB(21); B;
  20.     PRINT TAB(29);: PRINT USING "##.##"; DD(I);
  21.     PRINT TAB(35);: PRINT USING "####"; T(I)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Odd Data/Read syntax error
« Reply #2 on: November 30, 2019, 11:27:01 am »
Hi!!
Ya, just added that when you sent yours LOL
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Marked as best answer by xra7en on November 30, 2019, 07:18:17 am

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Odd Data/Read syntax error
« Reply #3 on: November 30, 2019, 11:51:43 am »
I wish we could get away with DIM A, B, C, D, ETC, AS STRING but then we would need a new syntax: AS STRINGS

Change it to...

DIM A AS STRING, B AS STRING

Sorry, I copied and pasted your code first, ran it, then hit reply. I should have looked for other replies first, to see the problem was solved. Oh well, blame it on too much Thanksgiving Day lasagna!

Pete
« Last Edit: November 30, 2019, 12:08:39 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: Odd Data/Read syntax error
« Reply #4 on: November 30, 2019, 12:18:08 pm »
LOL!! lasagna!!!!!
 You can't stuff lasagna :-)


BTW that was it!! thanks!

I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Odd Data/Read syntax error
« Reply #6 on: November 30, 2019, 01:24:28 pm »
LOL!! lasagna!!!!!
 You can't stuff lasagna :-)


BTW that was it!! thanks!

No, but you can use lasagna to stuff a Garfield.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Odd Data/Read syntax error
« Reply #7 on: November 30, 2019, 01:30:08 pm »
For what's it's worth, I do have a cat that eats lasagna, however unlike Garfield, she's a little spring. I have yet to beat her in a race down our stairs... well, without cheating by jumping off the balcony. With my luck, my tie would get caught on the railing, and I'd end up like that Epstein character, who supposedly committed suicide in his prison cell. The only difference is his jail cell had non-functioning video cameras, whereas my my home cam system works perfectly; so while his family had to start a go fund me page, mine would just submit our footage to America's Funniest Home Videos, for a sure bet of winning the grand prize!

Now what topic were we on again??? :D

Pete 
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/