ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
ASC and CHR$ Functions Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses ASC to display the the ASCII code of any key entered by
' the user. CHR$ is used to define the Escape key as the exit key.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 CLS                              ' Clear the screen
 PRINT TAB(20); "Press 'Escape Key' to END"
 PRINT : PRINT " Extended", "ASCII", "Description"
 PRINT " Code", "Code"
 VIEW PRINT 6 TO 23
 DO
     KeyPress$ = INKEY$
     SELECT CASE LEN(KeyPress$)
         CASE 0:                  ' Do nothing, since no key was pressed
         CASE 1:                  ' Standard ASCII key
             ASCII% = ASC(KeyPress$)
             PRINT , ASCII%, "Standard ASCII Key"
         CASE 2:                  ' Extended key (Scan + ASCII codes)
             SCAN% = ASC(LEFT$(KeyPress$, 1))
             ASCII% = ASC(RIGHT$(KeyPress$, 1))
             PRINT SCAN%; "+"; ASCII%, , "Extended Key"
     END SELECT
 LOOP UNTIL KeyPress$ = CHR$(27)