bas7ex.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 Function Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses INSTR and UCASE$ to determine a person's gender from
'their courtesy title (Mr., Mrs., or Ms.).
 
'Get a name.
CLS    'Clear screen.
DO
   INPUT "Enter name including courtesy title (Mr., Mrs., or Ms.): ", Nm$
LOOP UNTIL LEN(Nm$) >= 3
 
'Convert lowercase letters to uppercase.
Nm$ = UCASE$(Nm$)
'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
    'Can't determine sex, query user.
    DO
        INPUT "Enter sex (M/F): ", Sex$
        Sex$ = UCASE$(Sex$)
    LOOP WHILE Sex$ <> "M" AND Sex$ <> "F"
END IF
'Print result.
PRINT "Sex is "; Sex$
 
'Sample Output
'
'Enter name: Ms. Elspeth Brandtkeep
'Sex is F
'
'Enter name: Dr. Richard Science
'Enter sex (M/F): M
'Sex is M