Difference between revisions of "ASC (statement)"

From QB64 Wiki
Jump to navigation Jump to search
imported>Cyperium
imported>Odin
m (4 revisions imported)
 
(25 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The {{KW|ASC (statement)|ASC}} statement allows a '''QB64''' program to change a character at any position of a predefined {{KW|STRING}}.
+
The [[ASC (statement)|ASC]] statement allows a '''QB64''' program to change a character at any position of a [[STRING]] variable.
 
 
  
  
 
{{PageSyntax}}  
 
{{PageSyntax}}  
:<code>{{KW|ASC (statement)|ASC}}({{Parameter|string_expression$}}[, {{Parameter|position%}}]) = {{Parameter|code%}}</code>
+
: [[ASC (statement)|ASC]]({{Parameter|stringExpression$}}[, {{Parameter|position%}}]) = {{Parameter|code%}}
  
  
 
{{PageDescription}}
 
{{PageDescription}}
* The string expression must be predefined.
+
* The {{Parameter|stringExpression$}} variable's value must have been previously defined and cannot be an empty string ("").
* Position parameter is optional. If no position is used, the first position is assumed.
+
* {{Parameter|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({{KW|LEN}}) or an illegal function error will occur.
+
* {{Parameter|position%}} cannot be zero or greater than the string's [[LEN|length]] or an [[ERROR Codes|Illegal function error]] will occur.
* The {{KW|ASCII}} code% value can be any value from 0 to 255.
+
* 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}}
 
{{PageExamples}}
 
+
''Example:'' Demonstrates how to change existing text characters one letter at a time.
''Example:''
 
 
{{CodeStart}}
 
{{CodeStart}}
 
  a$ = "YZC"
 
  a$ = "YZC"
  {{KW|ASC (statement)|ASC}}(a$) = 65
+
  {{Cl|ASC (statement)|ASC}}(a$) = 65                 ' CHR$(65) = "A"
  {{KW|ASC (statement)|ASC}}(a$, 2) = 66
+
  {{Cl|ASC (statement)|ASC}}(a$, 2) = 66             ' CHR$(66) = "B"
  {{KW|PRINT}} a$ 'ABC
+
  {{Cl|PRINT}} a$ 'ABC
 +
 
 +
{{Cl|ASC (statement)|ASC}}(a$, 2) = 0              ' CHR$(0) = " "
 +
{{Cl|PRINT}} a$
  
  {{KW|ASC (statement)|ASC}}(a$, 2) = 0
+
  {{Cl|ASC (statement)|ASC}}(a$, 2) = {{Cl|ASC}}("S")        ' get code value from ASC function
  {{KW|PRINT}} a$
+
  {{Cl|PRINT}} a$
 
{{CodeEnd}}
 
{{CodeEnd}}
  
Line 30: Line 32:
 
  ABC
 
  ABC
 
  A C
 
  A C
 +
ASC
 
{{OutputEnd}}
 
{{OutputEnd}}
  
  
''See also:''
+
{{PageSeeAlso}}
 
+
* [[ASC]] {{text|(function)}}
{{KW|ASC}} (function), {{KW|ASCII}}
+
* [[MID$ (statement)]]
 
+
* [[_PRINTSTRING]]
 
+
* [[INKEY$]], [[ASCII]]
  
  
 
{{PageNavigation}}
 
{{PageNavigation}}

Latest revision as of 03:16, 1 November 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