Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrays: assign multiple values in one line?
#1
Hi all - I've recently come back to QBasic after a year or two of doing other things (kinda got annoyed with how it ran when we first got XP.... or was it Win2000? Well anyways). I'm looking at arrays, and wondering if there is a way to declare them in one line?

Right now I'm doing
Code:
DIM Array(3)
Array(1) = "Something"
Array(2) = "Something Else"
Array(3) = "Something Completely Different"
Now, I think there should be an easier way to do this that I'm probably just missing. I know in things like PHP or Java you can do
Code:
Array = ("Something", "Something Else", "Something Completely Different")

Any advice for how I'd do this in QBasic? (I'm hoping it's just a simple syntax I don't know). Thanks in advance. Smile
nce upon a time there crept through the looking-glass a curious child whose manners were not very good. Perhaps a little clever, yes, but given to spying, and sneaking, and going through dead men's pockets... [cloudmakers]
Reply
#2
either that or the DATA statments you said you didn't like =P
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
Or a file. Though it's a lil bit more trouble when coding it first time, you'll thank yourself later, because it's way more structered, and you will also save memory for real code.
url=http://www.copy-pasta.com]CopyPasta[/url] - FilePasta
Reply
#4
Quote:Or a file. Though it's a lil bit more trouble when coding it first time, you'll thank yourself later, because it's way more structered, and you will also save memory for real code.

Files = teh winnar.

Code:
dim myarray(50) as string

open myfile for input as #1
ctr = 0

while (ctr < 50) and not eof(1)
  ctr = ctr + 1
  line input #1, myarray$(ctr)
wend

close #1

If you do a lot of this, you may realise that too much file access will slow your program's initialization. It is significantly faster to make a few LINE INPUTs and then chunk it all up using MIDs or whatever. But for now, this works fine.

(and IIRC, windows provides some sort of disk caching that masks the effect... But if you load a 32k file one byte at a time, you'll notice it for sure.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)