Table of contents
TOC
Collapse the table of content
Expand the table of content

Asc Function

office 365 dev account|Last Updated: 6/12/2017
|
1 Contributor

Returns an Integer representing thecharacter code corresponding to the first letter in a string. SyntaxAsc(string) The required stringargument is any validstring expression. If the string contains no characters, arun-time error occurs. Remarks The range for returns is 0 - 255 on non-DBCS systems, but -32768 - 32767 on DBCS systems.

Note The AscB function is used with byte data contained in a string. Instead of returning the character code for the first character, AscB returns the first byte. The AscW function returns theUnicode character code except on platforms where Unicode is not supported, in which case, the behavior is identical to the Asc function.

Note Visual Basic for the Macintosh does not support Unicode strings. Therefore, AscW ( n ) cannot return all Unicode characters for n values in the range of 128 - 65,535, as it does in the Windows environment. Instead, AscW ( n ) attempts a "best guess" for Unicode values n greater than 127. Therefore, you should not use AscW in the Macintosh environment.

Example

This example uses the Asc function to return a character code corresponding to the first letter in the string.

Dim MyNumber
MyNumber = Asc("A")    ' Returns 65.
MyNumber = Asc("a")    ' Returns 97.
MyNumber = Asc("Apple")    ' Returns 65.

© 2018 Microsoft