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.
RIGHT$ Function Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'This example uses the RIGHT$ function to convert names input in the form
'"Firstname [Middlename] Lastname" to the form "Lastname, Firstname
'[Middlename]".
 
CLS                                  'Clear screen.
LINE INPUT "Name: "; Nm$
I = 1 : Sppos = 0
DO WHILE I > 0
    I = INSTR(Sppos + 1, Nm$, " ")   'Get position of next space.
    IF I > 0 THEN Sppos = I
LOOP
 
'Sppos now points to the position of the last space.
IF Sppos = 0 THEN
    PRINT Nm$                        'Only a last name was input.
ELSE
    'Everything after last space.
    Lastname$ = RIGHT$(Nm$, LEN(Nm$) - Sppos)
    'Everything before last space.
    Firstname$ = LEFT$(Nm$, Sppos - 1)
    PRINT Lastname$ ", " Firstname$
END IF
END