Posts: 383
Threads: 14
Joined: Mar 2004
I can't use QB for a few days, but I'm still writing code. I don't know if this works, but I would like to know. The .DAT file will contain data for a map (21x15):
[syntax="qbasic"]
dim shared Map(21,15)
input "Filename (no extension): ", filename$
open filename$ +".DAT" for input as #1
for yMap% = 1 to 15
for xMap% = 1 to 21
read #1, Map(xMap%, yMap%)
next xMap%
next yMap%
close #1
[/syntax]
Posts: 2,765
Threads: 138
Joined: Nov 2002
[syntax="QBASIC"]READ #1, Map(xMap%, yMap%)[/syntax]should be
[syntax="QBASIC"]INPUT #1, Map(xMap%, yMap%)[/syntax]
READ reads from DATA
INPUT inputs from files or user ^_^
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,774
Threads: 62
Joined: Aug 2003
You might also want to set the OPTION BASE to 1...
Code:
OPTION BASE 1
DIM SHARED Map(21 , 15)
or Dim the array like this....
Code:
DIM SHARED Map(1 to 21 , 1 to 15)
It will just save a tiny bit of memory on this, but it's good practice to only allocate what you need so the memory will be available for other things.
Posts: 383
Threads: 14
Joined: Mar 2004
Thanks White
Dr_D, never heard of OPTION BASE. What is it?
Posts: 6,419
Threads: 74
Joined: Mar 2002
RTFM
Anyhow, OPTION BASE is for compatibility. It just tells QB that the arrays begin with index #0 (default) or #1.
Btw, It's better to leave it to zero and code consequently. Less checks involved.
Posts: 383
Threads: 14
Joined: Mar 2004
So you tell me to read the manual, and then you explain it to me? LoL... Thanks :wink:
Posts: 6,419
Threads: 74
Joined: Mar 2002
RTFM is always a kind advice. It's faster: if you want to know something, looking it in the manual takes 30 seconds and waiting for a reply in a forum can take several hours.
Posts: 383
Threads: 14
Joined: Mar 2004
I haven't got QB here so I didn't mind waiting :wink:
But you're right, it's regularily a good advice