Qbasicnews.com

Full Version: Will this work?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
[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 ^_^
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. Wink
Thanks White Smile

Dr_D, never heard of OPTION BASE. What is it?
RTFM Wink

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.
So you tell me to read the manual, and then you explain it to me? LoL... Thanks :wink:
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.
I haven't got QB here so I didn't mind waiting :wink:
But you're right, it's regularily a good advice Smile