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.
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