-
edit names of variables
hello
as a beginner i have a - probaply - simple problem :
defined some variables like s1 = 12, s2 = 134 and so on
now in a for...next loop i want do work with this variables. on each loop which is counted with "i" its necessary to take the specified variable. so on run one its s1, on run two its s2 and so on.
because i work with a case statement to extract all the variables (i need many on each loop) i've got an code-cross-boundary-warning. (pbp 2.4.4)
the question: is it possible to build the name of the variable on the run instead a stiff code part. some thing like "s" and counter i merged to the name of the variable "s1"? or is it possible to build an array with the values and to refernce the record on each loop?
sorry, i can't find any information on the pbp-compiler manual...
greetings & thanks for a help
-
Hein?!? Not sure if i understand everything here.
Is it possible for you to post your code here? Will be more simple for us if we see what you made.
-
so the code seems so :
FOR i = 1 TO 35 !!!
SELECT CASE i
CASE 1
PORTC = s1+z1
....
CASE 2
PORTC = s2+z1
....
so and this 35 times... now i had found a solution with an array.
but i'm interested if it is possible with string manipulation too. so can i write something like that (php style) :
CASE 3
PORTC = "s".i+z1 ' same like PORTC = s3+z1 ?
"s" declares a string, the point merge them with counter i and results as s3
i have order a book about pic basic pro and waiting for. but i hadn't found a good basic reference online. does anyone know a good introduction to the syntax?
thanks again
-
o.k. for sure you can do it with an array or if your PIC has an internal EEPROM you can use it with WRITE/READ statement
Code:
MyArray VAR byte[35]
MyArray[0]=1
MyArray[1]=2
MyArray[2]=3
MyArray[3]=4
MyArray[4]=5
'.....
MyArray[34]=35
Start:
For i = 0 to 34
PORTC=MyArray[i]+z1
Next
With internal EEPROM
Code:
Mydata var byte
data @0,1,2,3,4,5,6...............35
Start:
For i = 0 to 34
READ i,MyData
PORTC=MyData+z1
Next
both will do the same result. The last one will eat less of your code space. Hope this help you :)