Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

QBasic - LB - Loading 2D Arrays

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> LB for MS-DOS BASIC Users
View previous topic :: View next topic  
Author Message
Robin
Guest





PostPosted: Oct 15th, 2009, 2:38pm    Post subject: QBasic - LB - Loading 2D Arrays Reply with quote

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: 728

PostPosted: Oct 15th, 2009, 5:32pm    Post subject: Re: QBasic - LB - Loading 2D Arrays Reply with quote

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
View user's profile Send private message Send e-mail
Raider
Guest





PostPosted: Oct 18th, 2009, 1:03pm    Post subject: 2D arrays = further to..... Reply with quote

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: 728

PostPosted: Oct 21st, 2009, 1:07am    Post subject: Re: QBasic - LB - Loading 2D Arrays Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> LB for MS-DOS BASIC Users All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group