Asc(), Chr()
This pair of functions converts between numbers and the ASCII character set. ASC(a character) returns the ASCII code number for that character, while CHR(a number) returns the character whose ASCII number you pass. Note that ASC() can take a whole character string as a parameter, but it returns the ASCII code of the first character in the string.
Usage |
nNumber = ASC( cString ) cChar = CHR( nNumber ) |
KEYBOARD CHR(13)But it's much more readable as:
KEYBOARD "{ENTER}"so we switched.ASC() is a handy hacker's tool for use in dissecting binary data. ASC() gives you the ability to convert a single character to numeric format. You can then use that number to perform binary math, splice and dice bits for calculations like timestamps, or add it to other numbers for multi-byte numeric conversion. While ASC() is valuable if the character is unknown, we don't use ASC() to check expected values. It's handy once in a while when you want to check a string for a special character that you can't write in curly brace notation, but it's just as easy to write:
IF LEFT(cString,1)=CHR(<some value>)as
IF ASC(cString)=<some value>and somehow, the first form seems more readable, so ASC() doesn't get much use.
See Also |