Difference between revisions of "ASC (statement)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Odin
imported>SMcNeill
(style guidelines)
Line 1: Line 1:
The '''ASC''' statement is used to change a character in a string variable into the specified '''ASC'''II code.
+
The [[ASC (statement)|ASC]] statement allows a '''QB64''' program to change a character at any position of a [[STRING]] variable.
  
== Syntax ==
 
'''ASC'''(stringVariable$[, position%]) = code%
 
  
== Example ==
+
{{PageSyntax}}
<source lang="qbasic">
+
: [[ASC (statement)|ASC]]({{Parameter|stringExpression$}}[, {{Parameter|position%}}]) = {{Parameter|code%}}
 +
 
 +
 
 +
{{PageDescription}}
 +
* The {{Parameter|stringExpression$}} variable's value must have been previously defined and cannot be an empty string ("").
 +
* {{Parameter|position%}} is optional. If no position is used, the leftmost character at position 1 is assumed.
 +
* {{Parameter|position%}} cannot be zero or greater than the string's [[LEN|length]] or an [[ERROR Codes|Illegal function error]] will occur.
 +
* The [[ASCII]] replacement {{Parameter|code%}} 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.
 +
 
 +
 
 +
{{PageExamples}}
 +
''Example:'' Demonstrates how to change existing text characters one letter at a time.
 +
{{CodeStart}}
 
  a$ = "YZC"
 
  a$ = "YZC"
  ASC(a$) = 65                ' CHR$(65) = "A"
+
  {{Cl|ASC (statement)|ASC}}(a$) = 65                ' CHR$(65) = "A"
  ASC(a$, 2) = 66              ' CHR$(66) = "B"
+
  {{Cl|ASC (statement)|ASC}}(a$, 2) = 66              ' CHR$(66) = "B"
  PRINT a$ 'ABC
+
  {{Cl|PRINT}} a$ 'ABC
  
  ASC(a$, 2) = 32              ' CHR$(32) = " "  
+
  {{Cl|ASC (statement)|ASC}}(a$, 2) = 0              ' CHR$(0) = " "  
  PRINT a$
+
  {{Cl|PRINT}} a$
  
  ASC(a$, 2) = ASC("S")        ' get code value from ASC function
+
  {{Cl|ASC (statement)|ASC}}(a$, 2) = {{Cl|ASC}}("S")        ' get code value from ASC function
  PRINT a$
+
  {{Cl|PRINT}} a$
</source>
+
{{CodeEnd}}
  
''Output:''
+
{{OutputStart}}
<pre>
 
 
  ABC
 
  ABC
 
  A C
 
  A C
 
  ASC
 
  ASC
</pre>
+
{{OutputEnd}}
 +
 
 +
 
 +
{{PageSeeAlso}}
 +
* [[ASC]] {{text|(function)}}
 +
* [[MID$ (statement)]]
 +
* [[_PRINTSTRING]]
 +
* [[INKEY$]], [[ASCII]]
 +
 
  
== Details ==
+
{{PageNavigation}}
* If position% isn't passed, '''ASC''' changes the leftmost character.
 

Revision as of 00:24, 10 September 2017

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


Syntax

ASC(stringExpression$[, position%]) = code%


Description

  • The stringExpression$ variable's value must have been previously defined and cannot be an empty string ("").
  • position% is optional. If no position is used, the leftmost character at position 1 is assumed.
  • position% cannot be zero or greater than the string's length or an Illegal function error will occur.
  • The ASCII replacement code% 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.


Examples

Example: Demonstrates how to change existing text characters one letter at a time.

a$ = "YZC" ASC(a$) = 65 ' CHR$(65) = "A" ASC(a$, 2) = 66 ' CHR$(66) = "B" PRINT a$ 'ABC ASC(a$, 2) = 0 ' CHR$(0) = " " PRINT a$ ASC(a$, 2) = ASC("S") ' get code value from ASC function PRINT a$

ABC A C ASC


See also



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page