Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Will this work?
#1
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]
Reply
#2
[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 ^_^
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
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
Reply
#4
Thanks White Smile

Dr_D, never heard of OPTION BASE. What is it?
Reply
#5
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#6
So you tell me to read the manual, and then you explain it to me? LoL... Thanks :wink:
Reply
#7
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#8
I haven't got QB here so I didn't mind waiting :wink:
But you're right, it's regularily a good advice Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)