Concatenate decimal variable and string?
Archiver
Posts: 46,084
In other languages I could tack a numeric value onto the end of a
string in various ways. Can't seem to figure out how in pbasic...
I use lookup to print a string on an LCD (Thanks to Al's book!) I
want to add a number onto the end of the string inside the lookup.
This is wrong, but it illustrates what I mean:
LOOKUP i,[noparse][[/noparse]"Loop Count "|ASC(Count),0],char
Or is this just not possible without more work than writing the
numeric seperately?
string in various ways. Can't seem to figure out how in pbasic...
I use lookup to print a string on an LCD (Thanks to Al's book!) I
want to add a number onto the end of the string inside the lookup.
This is wrong, but it illustrates what I mean:
LOOKUP i,[noparse][[/noparse]"Loop Count "|ASC(Count),0],char
Or is this just not possible without more work than writing the
numeric seperately?
Comments
characters. Why not define special characters for each value you might
want to print. So:
Top:
LOOKUP I,[noparse][[/noparse]"Loop Count is #.",0],char
If char<>"#" then dochar
For dc=3 to 0 step -1
char = (Count Dig dc) + "0"
gosub print_char
Next
Goto endloop
Dochar:
Gosub print_char
Endloop:
i=i+1
Goto top
If you have other things, you might do something like this:
Top:
LOOKUP I,[noparse][[/noparse]"Loop Count is # status=~",0],char
Nsel=255
Lookdown char,[noparse][[/noparse]"#","%","~","`"],Nsel
Branch Nsel,[noparse][[/noparse]docount,dov1,dov2,dov3]
Gosub print_char
Endloop:
i+i+1
goto top
Docount:
v=count
Dov:
For dc=3 to 0 step -1
char = (v Dig dc) + "0"
gosub print_char
Next
Goto endloop
Dov1:
v=v1
goto dov
Dov2:
v=v2
goto dov
' etc. etc.
The DIG operator takes the digit from the specified position. I've used
3 to 0 which would give you up to 9999. You could use 4 to 0 to get up
to 65535. I didn't supress leading zeros, but you could do something
like this:
Nozero var bit
Nozero=1
For dc=3 to 0 step -1
char = (v Dig dc) + "0"
if char="0" and dc<>0 and Nozero=1 then Digloop
Nozero=0
gosub print_char
Digloop:
Next
This correctly prints 0 and 1001, but it also prints 4 as 4 instead of
0004. Unless you are clearing your LCD, you might want the leading zeros
turned into blanks instead:
Nozero var bit
Nozero=1
For dc=3 to 0 step -1
char = (v Dig dc) + "0"
if char="0" and dc<>0 and Nozero=1 then leadspace
Nozero=0
Ploop:
gosub print_char
Digloop:
Next
Leadspace:
char=" "
goto ploop
All untested. Outlook capitalizes funny. Your milage may vary. Void
where prohibited by law.
Al Williams
AWC
* NEW: PAK-VIa - Read PS/2 keyboards or mice -- double the buffer, lower
current consumption.
http://www.al-williams.com/awce/pak6.htm
>
Original Message
> From: ghidera2000 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=vTsBEsSP3T9QPVQJwsWhuXvzYzmasZ77uZlKqJph1qcgyXOkbcLJgTEzj5tXrwgYbr8tPQtMhqesEGF3J0s]ghidera2000@y...[/url
> Sent: Thursday, October 10, 2002 12:24 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] Concatenate decimal variable and string?
>
>
> In other languages I could tack a numeric value onto the end of a
> string in various ways. Can't seem to figure out how in pbasic...
>
> I use lookup to print a string on an LCD (Thanks to Al's book!) I
> want to add a number onto the end of the string inside the lookup.
> This is wrong, but it illustrates what I mean:
>
> LOOKUP i,[noparse][[/noparse]"Loop Count "|ASC(Count),0],char
>
> Or is this just not possible without more work than writing the
> numeric seperately?
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>
>