bas7ex.hlp (Topic list)
SELECT Statement Programming Examples
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'These examples use the SELECT CASE statement to take different actions
'based on the input value.
 
'This example determines an investment strategy according to risk.
INPUT "Enter acceptable level of risk (1-10): ", Total
SELECT CASE Total
CASE IS >= 10
      PRINT "Maximum risk and potential return."
      PRINT "Choose stock investment plan."
CASE 6 TO 9
      PRINT "High risk and potential return."
      PRINT "Choose corporate bonds."
CASE 2 TO 5
      PRINT "Moderate risk and return."
      PRINT "Choose mutual fund."
CASE 1
      PRINT "No risk, low return."
      PRINT "Choose IRA."
CASE ELSE
      PRINT "Response out of range."
END SELECT
 
'Sample Output
'
'Enter acceptable level of risk (1-10): 10
'Maximum risk and potential return.
'Choose stock investment plan.
'
'Enter acceptable level of risk (1-10): 0
'Response out of range.
 
 
'This example uses the SELECT CASE statement to display messages
'based on the ASCII value of each input character.
 
'Function and control key constants.
CONST ESC = 27, DOWN = 80, UP = 72, LEFT = 75, RIGHT = 77
CONST HOME = 71, ENDKEY = 79, PGDN = 81, PGUP = 73
CLS
PRINT "Press Escape key to end."
DO
    'Get a function or ASCII key.
    DO
        Choice$ = INKEY$
    LOOP WHILE Choice$ = ""
 
    IF LEN(Choice$) = 1 THEN
        'Handle ASCII keys.
        SELECT CASE ASC(Choice$)
            CASE ESC
                PRINT "Escape key"
                END
            CASE IS < 32, 127
                PRINT "Control code"
            CASE 48 TO 57
                PRINT "Digit: "; Choice$
            CASE 65 TO 90
                PRINT "Uppercase letter: "; Choice$
            CASE 97 TO 122
                PRINT "Lowercase letter: "; Choice$
            CASE ELSE
                PRINT "Punctuation: "; Choice$
        END SELECT
 
    ELSE
        'Convert 2-byte extended code to 1-byte ASCII code and handle.
        Choice$ = RIGHT$(Choice$, 1)
 
        SELECT CASE Choice$
            CASE CHR$(DOWN)
                PRINT "DOWN arrow key"
            CASE CHR$(UP)
                PRINT "UP arrow key"
            CASE CHR$(PGDN)
                PRINT "PGDN key"
            CASE CHR$(PGUP)
                PRINT "PGUP key"
            CASE CHR$(HOME)
                PRINT "HOME key"
            CASE CHR$(ENDKEY)
                PRINT "END key"
            CASE CHR$(RIGHT)
                PRINT "RIGHT arrow key"
            CASE CHR$(LEFT)
                PRINT "LEFT arrow key"
            CASE ELSE
                BEEP
        END SELECT
    END IF
LOOP