Changing VAR names after declaration.
Archiver
Posts: 46,084
I often have to re-use the different variables in different
routines, but then it becomes hard to look back into the code some
days later.
Is it a way to rename the Variable names `on the fly?'
Ok, that was a stupid question, but since I edit the code, then
tokenize it.... It could bee a hidden solution to this question
within {$PBASIC 2.5} editor environment, before the code end up in
the BSp.
Stein
routines, but then it becomes hard to look back into the code some
days later.
Is it a way to rename the Variable names `on the fly?'
Ok, that was a stupid question, but since I edit the code, then
tokenize it.... It could bee a hidden solution to this question
within {$PBASIC 2.5} editor environment, before the code end up in
the BSp.
Stein
Comments
location in RAM. When you first compile a program, the variables are allocated
(by size, Words first) and a table of RAM addresses is created. This happens
during the compilation stage.
What PBASIC allows you to do, however, is give the same RAM location more than
one name. We call this aliasing. For example, try this:
var1 VAR Byte
var2 VAR var1 ' point to location assigned to var1
Test:
var1 = 0
var2 = 25
DEBUG ? var1
END
The code looks like it is manipulating two different variables but, in fact, it
is operating on the same RAM location. Keep this in mind when aliasing
variables so you don't end up with unexpected behaviors. One of the things you
can't do is alias an array, but since arrays are implicit in PBASIC variables
you can do this:
colors VAR Byte
red VAR colors ' point to location assigned to colors
green VAR Byte ' location is colors + 1
blue VAR Byte ' location is colors + 2
idx VAR Nib
Test:
FOR idx = 0 TO 2
colors(idx) = idx + 1
NEXT
DEBUG ? red
DEBUG ? green
DEBUG ? blue
END
Happy Holidays.
-- Jon Williams
-- Applications Engineer, Parallax
-- Dallas Office
Original Message
From: