Asc, AscB, AscW (functions)

Syntax

Asc(string)

AscB(string)

AscW(string)

Description

Returns an Integer containing the numeric code for the first character of string.

Comments

This function returns the character value of the first character of string.

On single-byte systems, this function returns a number between 0 and 255, whereas on MBCS systems, this function returns a number between -32768 and 32767. On wide platforms, this function returns the MBCS character code after converting the wide character to MBCS.

To return the value of the first byte of a string, use the AscB function. This function is used when you need the value of the first byte of a string known to contain byte data rather than character data. On single-byte systems, the AscB function is identical to the Asc function.

On platforms where BasicScript uses wide string internally (such as Win32), the AscW function returns the character value native to that platform. For example, on Win32 platforms, this function returns the UNICODE character code. On single-byte and MBCS platforms, the AscW function is equivalent to the Asc function.

The following table summarizes the values returned by these functions:

 

Function

String Format

Returns value of the:

 

Asc

 

First byte of string (between 0 and 255)

 

 

MBCS

First character of string (between -32769 and 32767)

 

 

Wide

First character of string after conversion to MBCS.

 

AscB

 

First byte of string.

 

 

MBCS

First byte of string.

 

 

Wide

First byte of string.

 

AscW

 

Same as Asc.

 

 

MBCS

Same as Asc.

 

 

Wide

Wide character native to the operating system.

Example

This example fills an array with the ASCII values of the string s components and displays the result.

Const crlf = Chr$(13) + Chr$(10)

Sub Main()

  s$ = InputBox("Please enter a string.","Enter String")
  If s$ = "" Then End    'Exit if no string entered.
msg1 = "" 

For i = 1 To Len(s$)

    msg1 = msg1 & Asc(Mid(s$,i,1)) & crlf
  Next i
  MsgBox "The Asc values of the string are:" & msg1
End Sub

See Also

Chr, Chr$ (functions).

More information

A