Read/Data 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!
Post Reply
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Read/Data error!

Post by Mentat »

Now, I've used data and read statements for quite some time. Now I'm getting a syntax error for my Read statement :x !

Here's my code:

FOR Y% = 1 TO NUMBER% 'number is the number of cubes
FOR X% = 1 TO 6 '6 sides of a cube
READ C% 'read some data
LET CUBES(Y, X) = C% 'store it to an array
NEXT X%
NEXT Y%

... blah

DATA 000, 000, 000, 000, 000, 000 'INTRO CUBE
DATA 000, 000, 000, 000, 000, 000
... more data

Have I forgotten something?
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Ohh... the compiler was looking at the remarks after Data. That would explain a lot.

Is there a way around this? I want to title my data.
For any grievances posted above, I blame whoever is in charge . . .
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Post by Mac »

Mentat wrote:Is there a way around this?
No. Anything after DATA is counted as data. There is no way to put a remark on a DATA line.

Of course, you can always do this
' Here is some data
DATA Blah
DATA Blah
' And here is some other data
DATA Blah

Mac
Dav
Coder
Posts: 14
Joined: Thu Jul 15, 2004 9:23 am
Contact:

Post by Dav »

The only way I know of adding remarks to the end of a DATA line is by putting a colon at the end of them, like this:

DATA 000, 000, 000, 000, 000, 000: 'INTRO CUBE
DATA 000, 000, 000, 000, 000, 000: 'ICE CUBE?

I didn't know about that trick until last year, and I don't think the QB manual even mentions it. It's in the QBKB here: http://kb.qbasicnews.com/Q36395.TXT

- Dav
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

Thanks a lot :D . But I might switch over to .DAT instead. See the Loading post.
For any grievances posted above, I blame whoever is in charge . . .
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Post by Mac »

Dav wrote:The only way I know of adding remarks to the end of a DATA line is by putting a colon at the end of them
Good point, Dav! I forgot about that.

And I usually always use colon before remarks to keep the spacing. I hate it when
x = 1 'First guy
becomes
x = 1'First guy
so I do
x = 1: ' First guy

I should have noted that this would apply to DATA also

Mac
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

People, please use code tags. It makes your post a lot easier to read, as some of you just randomly put code anywhere in your post, and sometimes it's hard to differentiate between the code and your post.

Code: Select all

[code]This is a code tag!
[/code]
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post by Mentat »

People, please use code tags
So that's what those buttons are for 8) .

please goto:

http://www.petesqbsite.com/forum/viewtopic.php?t=2428

I didn't post there just for fun. I KNOW somebody has the answer.
For any grievances posted above, I blame whoever is in charge . . .
Post Reply