Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

CHR$

Keyword Abbreviation Token (hex) Version(s) Classification
CHR$ C{Shift+H} C7 1.0+ Function

  Syntax  
CHR$ code )
 
Parameters Type Legal Value(s) Default Value Note(s)
code Integer
0 to 255
 
Returns Type Value(s) Note(s)
character String
1 character
the actual character depends on code
 
  Purpose  
Return the character which corresponds to a numeric code.

 
  Remarks  
The CHR$ function simply returns a string containg the character with the given code.  For a list of codes for the uppercase/graphics character set, see the ASCII-X page.  For a list of codes for the lowercase/uppercase character set, see the PETSCII page.  Actually the computer doesn't care which character set is used; but to the human viewing the characters, it can make a huge difference!  Also note those tables have some duplicates; generally you can use either code to generate such characters, but the ones marked "Primary" are recommended as some devices or other software may not understand the "Alternate" code.
 
The CHR$ function is especially usefull for generating characters that can't be entering as a literal value in a BASIC program: double-quote ("), RETURN, or NULL.
 
You will get TYPE MISMATCH ERROR with a string expression or variable given for the code (the VAL function may help).  A floating-point code will be converted to an integer (see INT).  An ILLEGAL QUANTITY ERROR is generated if the code is not a Legal Value (see table above).
  
Examples (uppercase/graphics character set):
PRINT CHR$("65")

?TYPE MISMATCH ERROR 
READY.
PRINT CHR$(65)
A

READY.
PRINT CHR$(193)
♠

READY.
  
Examples (lowercase/uppercase character set):
print chr$("65")

?type mismatch error 
ready.
print chr$(65)
a

ready.
print chr$(193)
A

ready.
   
  Compare With  
 
  Contrast With  
 
  See Also  

© H2Obsession, 2014
Comments