| .INSTR Function Programming Example. |
|
  QuickSCREEN       Details      Example       Contents       Index |
| ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ |
| INSTR Function Programming Example |
|
| This example uses INSTR and UCASE$ to determine a person's sex 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 |
|   |