Progress
Language Reference


ASC Function

Interfaces
OS
SpeedScript
All
All
Yes

Converts a character expression representing a single character into the corresponding ASCII (or internal code page) integer value.

SYNTAX

ASC ( expression
      [ , target-codepage [ , source-codepage ] ] ) 

expression

An expression with a value of a single character that you want to convert to an ASCII (or internal code page) integer value. If expression is a constant, you must enclose it in quotation marks (" "). If the value of expression is other than a single character, ASC returns the value -1.

The values for expression are case sensitive. For example, ASC("a") returns a different value than ASC("A").

target-codepage

A character-string expression that evaluates to the name of a code page. The name that you specify must be a valid code page name available in the DLC/convmap.cp file (a binary file that contains all of the tables that Progress uses for character management). If you supply a non-valid name, the ASC function returns the value -1 and returns a runtime error. Before returning an integer value, the ASC function converts expression from source-codepage to target-codepage. The returned integer value is relative to target-codepage. If you do not specify target-codepage, the value returned is the code page identified with the Internal Code Page (-cpinternal) parameter.

source-codepage

A character-string expression that evaluates to the name of a code page. The name that you specify must be a valid code page name available in the DLC/convmap.cp file. If you supply a non-valid name, the ASC function returns the value -1. The source-codepage specifies the name of the code page to which expression is relative. The default value of source-codepage is the code page identified with the Internal Code Page (-cpinternal) parameter.

EXAMPLE

The following procedure counts how many customers names begin with each of the letters, A-Z. It counts all other customers separately. The procedure uses the ASC function to translate a letter into an integer that it uses as an array subscript for counting.

r-asc.p
DEFINE VARIABLE ltrl AS INTEGER EXTENT 27.
DEFINE VARABLE i AS INTEGER.
DEFINE VARIABLE j AS INTEGER.FOR EACH customer:
  i = ASC(SUBSTRING(name,1,1)).
  IF i < ASC("A") or i > ASC("Z") THEN i = 27.
  ELSE i = i - ASC("A") + 1.
  ltrl[i] = ltrl[i] + 1.
END.DO j = 1 TO 27 WITH NO-LABELS USE-TEXT:
  IF j <= 26
  THEN DISPLAY CHR(ASC("A") + j - 1) @ ltr-name 
    AS CHARACTER FORMAT "x(5)".
  ELSE DISPLAY "Other" @ ltr-name.
  DISPLAY ltrl[j].
END. 

NOTES

SEE ALSO

CHR Function, CODEPAGE-CONVERT Function, INTEGER Function, SESSION System Handle


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095