GetInput 2/3

 BBS: Inland Empire Archive
Date: 01-03-93 (00:21)             Number: 347
From: VICTOR YIU                   Refer#: NONE
  To: IMRAN HAYAT                   Recvd: NO  
Subj: GetInput     2/3               Conf: (2) Quik_Bas
>>>>--- Continued from last message...

FUNCTION GetInput$ (Prompt$, MaxLen)

    IF MaxLen < 1 THEN MaxLen = 80 - LEN(Prompt$) - POS(0)
    ' 0 or -1 means all that will fit on the row
    ' Adjusts MaxLen to max. len to the end of the line if user
    ' passes in < 1
    PRINT Prompt$;      ' print prompt
    StartX = POS(0)     ' save cursor column, to use later as base
    Cursor = 1          ' init. cursor
    Insert = True       ' default mode: insert

    DO    ' start main loop
        IF Update THEN      ' True if something changed in input
            LOCATE , StartX, 0      ' locate at base
            PRINT Out$; SpaceBar$;        ' print input plus a space
            Update = False          ' reset flag
        END IF

        LOCATE , Cursor + StartX - 1, 1, (NOT Insert) * -7, 16
            ' locate cursor at end of text, with cursor on.
            ' cursor shape is dependent on insertion mode
        DO: I$ = INKEY$         ' wait for input
        LOOP UNTIL LEN(I$)      ' --> NOTE:
                                    ' using LEN(I$) is _MUCH_ faster than
                                    ' using I$ <> ""
        IF LEN(I$) = 1 THEN     ' branch according to len. of input
            Update = True       ' set flag to update

            SELECT CASE ASC(I$)
                CASE IS >= 32   ' a normal char: just add it to string
                    IF (NOT Insert) OR (LEN(Out$) < MaxLen)
THEN  ' within limits?
                    ' able to add anymore?
                        IF Cursor > 0 THEN    ' has user typed anything?
'                                Out$ = LEFT$(Out$, Cursor -
 1) + I$ + MID$(Out$, Cursor)
'                                Out$ = LEFT$(Out$, Cursor -
 1) + I$ + MID$(Out$, Cursor + 1)
                                Out$ = LEFT$(Out$, Cursor -
1) + I$ + MID$(Out$, Cursor - (NOT Insert))
                        ELSE
                            Out$ = I$    ' create new string
                        END IF
                        Cursor = Cursor + 1     ' advance cursor position
                    ELSE
                        Alarm           ' can't add, so beep at them
                        Update = False  ' don't update
                    END IF
                CASE 8          ' backspace
                    IF LEN(Out$) AND (Cursor > 1) THEN 'can we backspace?
                        Out$ = LEFT$(Out$, Cursor - 2) +
MID$(Out$, Cursor)  ' remove 1 char. before cursor
                        Cursor = Cursor - 1     ' adjust cursor
                    ELSE
                        Alarm
                        Update = False
                    END IF
                CASE 13     ' enter
                    EXIT DO
                CASE 27     ' escape
                    IF LEN(Out$) > 0 THEN     ' has user typed anything?
                        LOCATE , StartX, 0    ' yes, so clear the string
                        PRINT SPACE$(LEN(Out$) + 1);

                        Out$ = ""
                        Cursor = 1      ' resetting cursor position
                        Update = False  ' don't update:  no reason to
                    ELSE
                        EXIT DO         ' if nothing, just exit
                    END IF
            END SELECT
        ELSE    ' extended ASCII code
            SELECT CASE I$
                CASE LeftK$
                    IF Cursor > 1 THEN
                        Cursor = Cursor - 1     ' move cursor left
                    ELSE
                        Alarm
                    END IF
                CASE RightK$
                    IF Cursor < LEN(Out$) + 1 THEN
                        Cursor = Cursor + 1     ' move cursor right
                    ELSE
                        Alarm
                    END IF
                CASE Delete$
                    IF LEN(Out$) > 0 AND (Cursor < LEN(Out$)) THEN
                        Out$ = LEFT$(Out$, Cursor - 1) +
MID$(Out$, Cursor + 1)
                        Update = True
                    ELSE
                        Alarm
                    END IF

>>>>>>>>>------------- continued on last message...

--- Blue Wave/RA v2.10 [NR]
 * Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690
/ RA 1.11 / (1:106/30.0)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET