ex.hlp (Topic list)
INSTR and UCASE$ Function Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses INSTR and UCASE$ to determine a person's gender from
' the courtesy title (Mr., Mrs., or Ms.).
 
' 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
 DO                             ' Get a name
     INPUT "Enter name including courtesy title (Mr., Mrs., or Ms.): ", Nm$
 LOOP UNTIL LEN(Nm$) >= 3
 
 Nm$ = UCASE$(Nm$)              ' Convert lowercase letters to uppercase
                                ' Look for MS, MRS, or MR to set Sex$.
 IF INSTR(Nm$, "MS") > 0 OR INSTR(Nm$, "MRS") > 0 THEN
     Sex$ = "F"
 ELSEIF INSTR(Nm$, "MR") > 0 THEN
     Sex$ = "M"
 ELSE
     DO                         ' Can't determine sex, query user
          INPUT "Enter sex (M/F): ", Sex$
          Sex$ = UCASE$(Sex$)
     LOOP WHILE Sex$ <> "M" AND Sex$ <> "F"
 END IF
 PRINT "Sex is "; Sex$          ' Print result