ASC function

Purpose: ASC returns the ASCII value of a character.


 Syntax:

 RetVal% = ASC(Character$, [Index%])

 Parameters:

  • Character$ String literal containing any printable character or a string variable containing a character in the ASCII code range 0 to 255. If the string contains more than one character only the value of the first character in the string will be returned.
  • Index% [OPTIONAL] is an integer which specifies the location of the character for which the ASCII value is to be returned. The Index% value of the first character is 0, the second character 1 and so on.

 Return Value:

  • RetVal% Returned integer containing ASCII code.

Example 1 : This example will return the ASCII value for "A", the first character in the string "ABC".


 DIM RetVal%
 
 RetVal% = ASC("ABC")
 
 PRINT RetVal%

Result:

65

Example 2 : This example will return the ASCII value for "C", the third character in the string "ABC".


 DIM RetVal%
 
 RetVal% = ASC("ABC", 2)
 
 PRINT RetVal%

Result:

67

Remarks: CHR$ is a function complementary to ASC. CHR$ returns the literal character when given an ASCII integer argument.

BCX Console Sample Programs using ASC function.

S33.bas S75.bas