Name
Asc, AscB, AscW Functions
Syntax
Asc(string) AscB(string) AscW(string)
-
string Use: Required
Data Subtype: String
Any expression that evaluates to a string.
Return Value
An integer that represents the character code of the first character of the string. The range for the returned value is 0-255 on non-DBCS systems, but -32768-32767 on DBCS systems.
Description
Returns the ANSI (in the case of Asc) or Unicode
(in the case of AscW ) character code that
represents the first character of the string passed to it. All other
characters in the string are ignored. Use AscB
with Byte data and AscW on Unicode (DBCS)
systems.
Rules at a Glance
The string expression passed to the function must contain at least one character, or a runtime error (either “Invalid use of Null” or “Invalid procedure call or argument”) is generated.
Only the first character of the string is evaluated by
Asc,AscB, andAscW.Use the
AscWfunction to return the Unicode character of the first character of a string.Use the
AscBfunction to return the first byte of a string containing byte data.
Example
<%
Dim sChars
Dim iCharCode
sChars = Request.Form("chars")
If Len(sChars) > 0 Then
CharCode = Asc(sChars)
If iCharCode >= 97 And iCharCode <= 122 Then
Response.Write "The first character must be uppercase"
Else
Response.Write iCharCode
End If
End If
%>Programming Tips & Gotchas
Always check that the string you are passing to the function contains at least one character using the
Lenfunction, as the following example shows:If Len(sMyString) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access