Skip to content

ASC (statement)

github-actions[bot] edited this page Jun 16, 2022 · 5 revisions

The ASC statement allows a QB64 program to change a character at any position of a STRING variable.

ASC([,]) =
  • The variable's value must have been previously defined and cannot be an empty string ("").
  • is optional. If no position is used, the leftmost character at position 1 is assumed.
  • cannot be zero or greater than the string's length or an Illegal function error will occur.
  • The ASCII replacement value can be any INTEGER value from 0 to 255.
  • Some ASCII control characters will not PRINT a character or may format the SCREEN. _PRINTSTRING can print them graphically.
Example: Demonstrates how to change existing text characters one letter at a time.
 a$ = "YZC"
 {{Cl|ASC (statement)|ASC}}(a$) = 65                 ' CHR$(65) = "A"
 {{Cl|ASC (statement)|ASC}}(a$, 2) = 66              ' CHR$(66) = "B"
 {{Cl|PRINT}} a$ 'ABC
 {{Cl|ASC (statement)|ASC}}(a$, 2) = 0               ' CHR$(0) = " " 
 {{Cl|PRINT}} a$
 {{Cl|ASC (statement)|ASC}}(a$, 2) = {{Cl|ASC}}("S")        ' get code value from ASC function
 {{Cl|PRINT}} a$
 ABC
 A C
 ASC

Clone this wiki locally