PreviousNextIndex

ASC function

Converts a character expression representing a single character into the corresponding ASCII (or internal code page) value, returned as an INTEGER.

Syntax

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

expression
target-codepage
source-codepage
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 ix   AS INTEGER NO-UNDO. 
DEFINE VARIABLE jx   AS INTEGER NO-UNDO. 
DEFINE VARIABLE ltrl AS INTEGER NO-UNDO EXTENT 27. 
FOR EACH Customer NO-LOCK: 
  ix = ASC(SUBSTRING(Customer.Name,1,1)). 
  IF ix < ASC("A") or ix > ASC("Z") THEN ix = EXTENT(ltrl). 
  ELSE ix = ix - ASC("A") + 1. 
  ltrl[ix] = ltrl[ix] + 1. 
END. 
DO jx = 1 TO EXTENT(ltrl) WITH NO-LABELS USE-TEXT: 
  IF jx <= 26 THEN 
    DISPLAY CHR(ASC("A") + jx - 1) @ ltr-name AS CHARACTER FORMAT "x(5)". 
  ELSE  
    DISPLAY "Other" @ ltr-name. 
  DISPLAY ltrl[jx]. 
END. 

Notes
See also

CHR function, CODEPAGE-CONVERT function, INTEGER function, SESSION system handle


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex