Using a Variable in a String
Scott E
Posts: 7
Can someone explain how to use a variable in a "string". If you use a constant it works fine.
See example below
Thanks
Scott
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
z=$31
Var
Long x
Long y
OBJ
text : "tv_text"
num : "numbers"
PUB start | i
'start term
text.start(12)
x:=$31
'This will work
text.str(string(13," Z=",z))
'This will not work
text.str(string(13," X=",x))
See example below
Thanks
Scott
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
z=$31
Var
Long x
Long y
OBJ
text : "tv_text"
num : "numbers"
PUB start | i
'start term
text.start(12)
x:=$31
'This will work
text.str(string(13," Z=",z))
'This will not work
text.str(string(13," X=",x))
Comments
This is a little more work and doesn't look as nice, but it does work.
Thanks for your reply. I figured as much but would rather someone with a little more experience confirm it.
Scott
My format object may help somewhat. You can read about it here. With it, you can combine the str, dec, and other functions into a single call, using a C-like (printf) structure.
-Phil
Thanks for the tip on your format object. When I first looked at it, it was quite confusing but after spending a few minutes reading the description it became quite clear.
This object should improve the efficiency. May have to print out your description and keep it handy until it becomes 2nd nature but a lot sure can be done with one line of code
M.K. Borri I sure would like to see what you have been working on as well.
Thanks to both of you
This works for me; I don't know if it'll help you. It was written as part of a TV-based HP calculator emulator that my lab manager asked me to put together.
What happens is that, for example,
ExpressionParserRPN(string("4 5 + 3 *"), false, false)
will return 27.0 (the Mark parameter zeroes out the input string, that exists for application-specific reason), and
var
long DataAddress[noparse][[/noparse]26]
code
ExpressionParserRPN(string("4 5 + 3 * B +"), @DataAddress, false)
will return 27.0 plus whatever float is at the address @DataAddress + 4 , which can be a constant specified with a dat block, or a variable. This limits to A...Z variables, but that's because "it was good enough at the time" essentially...
As always, if you have any suggestions, please share [noparse]:)[/noparse]