News:

Let's find out together what makes a PIC Tick!

Main Menu

Digital Var to ASCII Chr

Started by Peter Truman, Dec 02, 2023, 05:30 AM

Previous topic - Next topic

Peter Truman

HI - I feel I should know this but.....

How do I print the Ascii chr represented by a digital variable?

I've tried to make sense of all the strn, STR, STR$ etc but these seem mostly preoccupied with converting an ASCII chr to a digital value?

I have a menu routine that need to print the chr "A" to "Z" based on the digital value 65-90

example output I need
Hrsout2 "The selected ID is ",A,13


I can see how I could do this with a string of 26 elements (from A-Z) then just use the variable to pick out a particular element - but that doesn't seem very efficient?

S_My_ID= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Hrsout2 "The selected ID is ",S_My_ID[VAR],13

I'm really only interested in the number - the A-Z thing is just a convenient means of identifying something.


Really appreciate your help


JonW

#1
Use DEC modifier, it converts the variable to ASCII

Example

Dim VAR as BYTE

Var = 123
Hrsout "VAR = ", DEC VAR

Output will be VAR = 123

DEC can also have a number after it to limit the digits, DEC2 prints 2 decimals


Edit:

  I think I have misinterpreted the question.  If you want to print the ascii representation then just send the number without a modifier. ie if VAR = 65 (Decimal) then the terminal will print A
VAR = 65                     ' DECIMAL
HRSOUT VAR,13,10              ' Terminal will print A, plus a Carriage Return and line feed (13,10)

Peter Truman

Hi John

So there we are - I spend the whole afternoon trying to figure out which combination of modifiers I need - only to discover that I didn't need a modifier at all!  :o  8)

Just tested it and it does indeed do exactly what you said.

Many thanks - and greetings from Sunny Tasmania!

JonW

No Worries. We all do these things

OOHSH  it works x J