Qbasicnews.com

Full Version: DIM arrays trouble
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Z!re helped me with this yesterday but I'm having trouble getting an INPUT to read all the arrays in a file with out having to name the strings$ over and over again.. This is kinda hard to explain so here is some code.

Code:
INPUT "Scale name to open: (no extensions) ", scale$
filename$ = scale$ + ".scl"
OPEN filename$ FOR INPUT AS #1
LINE INPUT #1, scalename$
p = 1
DIM a(150) AS STRING
DO
p = p + 1
INPUT #1, a$
LOOP UNTIL EOF(1)
CLOSE #1
PRINT a$, p, a

here's the file I'm reading from

Code:
E Plentonic
e 3, e 5, e 7, b 3, b 5, g 4, d 5, d 7, a 5 a 7, E 3, E 5, E 7
e 5, e 7, b 5, b 8, g 7, d 5, d 7, d 9, a 5, a 7, E 5, E 7
e 7, e 10, b 8, b 10, g 7, g 9, d 7, d 9, a 7, a 10, E 7, E 10
e 10, e 12, b 10, b 12, g 12, d 12, d 14, a 10, a 12, a 14, E 10, E 12
e 12, e 15, b 12, b 15, g 12, g 14, d 12, d 14, a 12, a 14, E 12, E 15

I want all those to be printed in QB, but i can only get the last variable (E 15) to print. Can someone alter the code to make it print out all those variables right there? Thanks Smile
Code:
INPUT "Scale name to open: (no extensions) ", scale$
filename$ = scale$ + ".scl"
OPEN filename$ FOR INPUT AS #1
LINE INPUT #1, scalename$
p = 0
DIM a(150) AS STRING
DO
p = p + 1
INPUT #1, a(p - 1)
LOOP UNTIL EOF(1)
CLOSE #1
FOR I = 0 TO 150
PRINT a(I)
NEXT I
I only changed all a$ in your code to actual array references a(). Wink Hope it works... Smile
Thanks Neo, it worked, but that wasn't exactly what I needed. How can I store each of those variables in array, and then print them outside of the FOR...NEXT loop?
easy!
Code:
PRINT a(1)
PRINT a(2)
PRINT a(3)
PRINT a(4)
PRINT a(5)
PRINT a(6)
PRINT a(7)
PRINT a(8)
PRINT a(9)
[...]
PRINT a(148)
PRINT a(149)
PRINT a(150)

or dont use a FOR NEXT loop

Code:
DO
PRINT a(p)
p = p + 1
LOOP UNTIL p = UBOUND(a) + 1 'I think


or just use a FOR NEXT loop...

Code:
FOR p = LBOUND(a) TO UBOUND(a) 'i also thionk
PRINT a(p)
NEXT p
I used a FOR .. NEXT loop in my code to print out all 150 variables... :???:

Oh well Wink