| .SELECT Statement Programming Examples. |
|
  QuickSCREEN       Details      Example       Contents       Index |
| ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ |
| SELECT Statement Programming Examples |
|
| There are two SELECT CASE programming examples. |
|   |
| Example 1 |
|   |
| In the following program, the SELECT CASE statement is used to take |
| different actions based on the input value: |
|   |
| ' Program demonstrates various forms of CASE items |
|      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 |
|   |
| Example 2 |
|   |
| In the following program, the SELECT CASE statement is used to take |
| different actions based on the ASCII value of a 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 |
|   |
| 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 30 TO 29 |
|                 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 |