ASC

ASC(string)

Returns the ASCII / ANSI number for the first character in a text string (Integer).


stringThe text string (String).

REMARKS
* The value returned is in the range 0 to 255.
* The ASCII Character codes use the values 0 to 127.
* The ANSI Character codes use the values 0 to 255.
* The "string" can be any valid string expression.
* If "string" is longer that one character, then the other characters are ignored.
* If "string" = "", then a run-time error occurs.
* The length of a string in bytes may be greater than or equal to the number of actual characters in the string.
* Use Asc("y") = x rather than Chr(y) = x
* Use IsCharAlphaNumeric instead of Asc() ?
* The value returned is in the range -32768 - 32767 for double byte character sets.
* VBA for Macintosh does not support Unicode Strings.
* You can use the ASCB function to return the first byte.
* You can use the ASCW function to return the Unicode number for the first character in a text string.
* You can use the CHR function to return the character with the corresponding ASCII / ANSI number.
* You can use the CHRW function to return the character with the corresponding Unicode number.
* The equivalent .NET function is [[Microsoft.VisualBasic.Strings.Asc]]
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Asc(0)           '= 48  
Debug.Print Asc(1) '= 49
Debug.Print Asc(9) '= 57
Debug.Print Asc("A") '= 65
Debug.Print Asc("Avocados") '= 65
Debug.Print Asc("Z") '= 90
Debug.Print Asc("a") '= 97
Debug.Print Asc("z") '= 122
Debug.Print Asc(12) '= 49

Dim iValue As Integer
iValue = Asc("x")
Debug.Print iValue '= 120

Debug.Print Asc(Chr(65)) '= 65

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top