View previous topic :: View next topic |
Author |
Message |
Robin Guest
|
Posted: Oct 15th, 2009, 2:38pm Post subject: QBasic - LB - Loading 2D Arrays |
|
|
I'm at Novice level for LB but trying to convert some hard copy QBasic code
to run in LB comprising lines of 6 numbers.
I've typed it in as is but filling a 2 Dimensional Y20 by X6 array with Data gives me a problem. With QBasic one defines array and types the 20 lines of data with the statement DATA in front of each line.
DIM CH(1 TO 20, 1 TO 6)
FOR Y = 1 TO 20
FOR X = 1 TO 6
READ CH (Y,X)
NEXT X
NEXT Y
[20 DATA LINES List to be READ in follows not shown]
I'm sure it must be as easy in LB but I have not (yet)
found a clear example as mostly STRINGS are used.
I've got quite a bit of LB code working
But not got to the "FUN" stage yet. |
|
Back to top |
|
|
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Oct 15th, 2009, 5:32pm Post subject: Re: QBasic - LB - Loading 2D Arrays |
|
|
Hi Robin,
Your QBasic code would have to be translated as the following:
Code: | DIM CH(20, 6)
FOR Y = 1 TO 20
FOR X = 1 TO 6
READ temp: CH(Y,X) = temp
NEXT X
NEXT Y |
LB doesn't allow array indeces to start with anything but zero, so therefore doesn't permit ranges.
LB 4.03 (and earlier) also cannot READ directly into an array element. You have to READ into a dummy variable then copy to the array element.
HTH _________________ Brent |
|
Back to top |
|
|
Raider Guest
|
Posted: Oct 18th, 2009, 1:03pm Post subject: 2D arrays = further to..... |
|
|
Brent,
Thank you for the information - which I find a bit suprising as QBasic achieves it so simply.
I have looked in two books that show LB programming procedures
also the LB Help and Alyce's LB Companion. Athough they mention
a lot about arrays and loading not one of them gives an example
of your suggested method for solving my problem. I am hoping to go up to
two arrays when I have proved my S/W works these will be around 200 lines
each.
I need to see a small but COMPLETE example to include copying from the Temp array into my designated one or perhaps you could guide me to a suitable source.
Thanks. |
|
Back to top |
|
|
Brent Site Admin
Joined: 01 Jul 2005 Posts: 800
|
Posted: Oct 21st, 2009, 1:07am Post subject: Re: QBasic - LB - Loading 2D Arrays |
|
|
Robin, there's no need to use a temp array. The temp I referred to is the variable used in the READ statement. Please notice the assignment immediately to the right of the READ in my code. _________________ Brent |
|
Back to top |
|
|
|