ASC function

Purpose

Return the ASCII code of the specified character in a string.

Syntax

y = ASC(string_expression [, position&])

Remarks

ASC returns the ASCII code (0 to 255) of the specified character of string_expression.  The first character of the string is position one, followed by position two, etc.  If position& is not specified then the first character is presumed.  If position& is a negative number, ASC counts from the end of the string back toward the front.  For example, if position& is -1 then the last character is returned.  If position& is -2 then the second from last character is returned, and so on.

The acronym ASCII stands for American Standard Code for Information Interchange, a standardized code in which the numbers between 0 and 127 are used to represent the upper and lowercase letters, the numerals 0 to 9, punctuation marks, and other symbols used in data communication.  PCs employ an extended version of ASCII, which contains codes 0 through 255.  The "upper" 128 codes (128-255) are not standard ASCII codes, and may differ from one country to another, and from code page to code page.

CHR$ does the reverse of ASC - it produces the one-character string corresponding to its ASCII code argument.

Restrictions

If the string passed is null (zero-length) or the position is zero or greater than the length of the string, the value -1 is returned.

See also

ASC statement, CHR$

Example

x$ = "The ASCII value of A is" + STR$( ASC("A") )

Result

The ASCII value of A is 65