BasicMicro - Forums

www.basicmicro.com
It is currently Sun May 20, 2012 11:50 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: using alaise Varabiables with array variables
PostPosted: Tue Jan 19, 2010 12:44 pm 
Offline
New User

Joined: Sat Dec 20, 2008 3:37 pm
Posts: 4
I have a routine that reads in 14 bytes from a serin command and correctly asigns the values to MED(0), Med(1),....... MED(13) . However when I try and assign an Aliase name to one of these array variables with the command Sensor VAR MED(3) It creates 3 variables (Sensor(0) , Sensor(1), Sensor(2), With only Sensor (0) holding the correct vaue. All the other variables Sensor(1), Sensor(2), contain zeros. So when I get to Thigh1 VAR med (13) it appears in IDE variable window that I now have Thigh1(0) thru Thigh1(12) used up . This ends up using 92 or so variable spaces. I could use the original arrays names in the program, but meaningful variable names goes a long way to make the code readable and understandable. SO are these Variables created and use up memory space or is this a bug in the IDE ? IDE is 05.3.10 IF it truly used up this variable sapce any way to work around the problem.
As usual any help in greatly appricated Thank you in advance Russ


Top
 Profile  
 
 Post subject: Re: using alaise Varabiables with array variables
PostPosted: Tue Jan 19, 2010 4:41 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
Hello Russ. Sounds like you want to do:
Code:
looper var byte  ; something to use in loops < 256
Med = byte(14)  ; creates a 14 byte array, Med(0) to Med(13)
Sensor var byte  ; byte space for "Sensor"
Thigh1 var byte  ; byte space for "Thigh1"

For looper = 0 to 13
   Med(looper) = looper  ; fill each "Med" array cell with looper value, so Med(0) = 0, Med(1) = 1, Med(2) = 2, etc.
next

Sensor = Med(3)  ; Sensor now equals 3
Thigh1 = Med(13)  ; Thigh1 now equals 13

END  ; just in case

And that's that.
The compiler now sets 17 bytes aside for variable storage. The compiler and run time don't keep track of index values, so you can overrun arrays at will. At this point you could literally refer to Thigh1 as Med(15) in your code, thus:
Sensor = Med(15)
will put Thigh1's value in Sensor. So you have to be careful about that and making loops as above too large. If you had made "looper" 0 to 255 it would have gone deep into your available RAM putting bogus values into bogus array locations.
Take care.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: using alaise Varabiables with array variables
PostPosted: Sat Jan 23, 2010 8:42 am 
Offline
New User

Joined: Sat Dec 20, 2008 3:37 pm
Posts: 4
Thanks for the reply
So as I understand it if I put the looper routine at the beginning of the program to set up the varaibles as you describe
I will end up with

ID pointing to MED(3)
'
'
'
.
Thigh1 pointing to MED(11)
Tlow1 pointing to MED(12)
SENSOR pointing to MED(13)
Etc.

NOW if later in the program I execute the line

serin RX_IN,N4800, 45535000, Timeout [str MED14] to read in 14 bytes to the array MED(0),MED(1),.......MED(13)

Will the Alaised variables point to the array values just read in by the above Serin command ?

Thanks Russ


Top
 Profile  
 
 Post subject: Re: using alaise Varabiables with array variables
PostPosted: Sat Jan 23, 2010 9:36 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
It Should!

Kurt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO