Return to Index  

Here's one with a clock in the title bar.

June 17 2017 at 9:55 PM

Pete  (Login The-Universe)
Admin


Response to How do I limit user input

 
The clock will keep running while the input is being typed. It is a custom keyboard input routine, which is a way around the limitations of the INPUT statement. It is limited to 10-character input by the variable: maxspaces.

Have fun trying it out.

- Pete

---------------------------------------------------

maxspaces% = 10
WIDTH 80, 25
DO
    CLS
    LOCATE 10, 5
    PRINT "Input Name: ";
    showcursor% = 7 ' Use 7 to show the cursor or zero to hide it. A value of 30 makes it a small square.

    CALL getinput(word$, maxspaces%, limitinput$, showcursor%, autoenter%)

    LOCATE 12, 5: PRINT "The input is now in the variable word$ as: "
    LOCATE 14, 41 - LEN(word$) / 2 ' Centers the print in the next line.
    PRINT word$

    ' Now here is another way to use the sub and keep the clock running.
    LOCATE 16, 5
    PRINT "Try again? Y/N "; ' Remember to always use a ";" after the print statement to keep your input on the same line.
    limitinput$ = "YyNn"
    autoenter% = 1 ' Automatically enter response after one key is pressed.
    showcursor% = 0 ' Hide the cursor for yes/no responses.

    CALL getinput(word$, maxspaces%, limitinput$, showcursor%, autoenter%)

    limitinput$ = "" ' Always erase variable for other uses.
    autoenter% = 0 ' Always erase variable for other uses.
    IF LCASE$(word$) = "n" THEN END
LOOP

SUB getinput (word$, maxspaces%, limitinput$, showcursor%, autoenter%)
' Input Statement with clock.
startpos% = POS(0)
endpos% = startpos% + maxspaces%
word$ = "" ' Erases last entry to begin next entry.
LOCATE , , 1, 7, showcursor%

DO
    IF TIME$ >= "12:00:00" THEN
        TIME1 = ASC(MID$(TIME$, 1, 1)) - 1
        TIME2 = ASC(MID$(TIME$, 2, 1)) - 2
        IF TIME2 < 48 THEN TIME2 = TIME2 + 10: TIME1 = TIME1 - 1
        TIMECONV$ = CHR$(TIME1) + CHR$(TIME2) + MID$(TIME$, 3, LEN(TIME$)) + " PM"
    ELSE
        TIMECONV$ = MID$(TIME$, 1, 8) + " AM"
    END IF
    IF MID$(TIMECONV$, 1, 2) = "00" THEN MID$(TIMECONV$, 1, 2) = "12"
    _TITLE SPACE$(61) + TIMECONV$

    ' KEY INPUT GOES HERE....................................................

    IF autoenter% THEN
        ' Used for a non-enter response, like answering yes or no.
        IF LEN(word$) = autoenter% THEN EXIT SUB
    END IF

    mykey$ = INKEY$

    IF mykey$ <> "" THEN
        yy% = CSRLIN: xx% = POS(0)

        SELECT CASE mykey$
            CASE CHR$(0) + "K"
                mov% = -1: GOSUB action
            CASE CHR$(0) + "M"
                mov% = 1: GOSUB action
            CASE CHR$(0) + "S"
                GOSUB wash: GOSUB delete
            CASE CHR$(0) + "R"
                IF ins% = 0 THEN ins% = -1 ELSE ins% = 0
                IF ins% = 0 THEN LOCATE , , 1, 7, 7 ELSE LOCATE , , 1, 7, 30
            CASE CHR$(0) + "O"
                IF word$ <> "" THEN LOCATE yy%, startpos% + LEN(word$)
            CASE CHR$(0) + "G"
                LOCATE yy%, startpos%
            CASE CHR$(8)
                IF xx% > startpos% THEN
                    LOCATE , POS(0) - 1
                    xx% = POS(0)
                    GOSUB wash: GOSUB delete
                END IF
            CASE CHR$(13)
                ' Exits the input sub back to your main program.
                EXIT SUB
            CASE CHR$(27)
                ' Quit and removes program winsow.
                SYSTEM
            CASE CHR$(32) TO CHR$(126)
                IF INSTR(limitinput$, mykey$) OR limitinput$ = "" THEN
                    key$ = mykey$
                    GOSUB action
                ELSE
                    BEEP ' Input error, retry.
                END IF
        END SELECT
        mov% = 0: key$ = ""
    END IF
LOOP

action:
IF POS(0) + mov% >= startpos% AND POS(0) + mov% < endpos% THEN
    DO
        IF key$ <> "" THEN
            SELECT CASE ins%
                CASE 0
                    IF LEN(word$) + LEN(key$) > endpos% - startpos% THEN EXIT DO
                    word$ = MID$(word$, 1, POS(0) - startpos%) + key$ + MID$(word$, POS(0) - startpos% + 1)
                CASE -1
                    word$ = MID$(word$, 1, POS(0) - startpos%) + key$ + MID$(word$, POS(0) - startpos% + 2)
            END SELECT
        END IF
        IF POS(0) - startpos% >= LEN(word$) - LEN(key$) AND key$ <> "" OR key$ = "" OR ins% = -1 THEN
            IF key$ = "" AND mov% = 1 THEN IF POS(0) - startpos% = LEN(word$) THEN EXIT DO
            LOCATE , POS(0) + mov%: PRINT key$;
        ELSE
            LOCATE yy%, startpos%: PRINT MID$(word$, 1, xx% - startpos%); key$;: xx2% = POS(0): PRINT MID$(word$, xx% - startpos% + 2);: LOCATE yy%, xx2%
        END IF
        EXIT DO
    LOOP
END IF
RETURN

wash:
IF POS(0) >= startpos% AND word$ <> "" AND POS(0) - startpos% < LEN(word$) THEN
    LOCATE yy%, startpos% + LEN(word$) - 1
    PRINT " ";
    LOCATE yy%, xx%
END IF
RETURN

delete:
IF POS(0) - startpos% = 0 THEN
    word$ = MID$(word$, 2)
ELSE
    word$ = MID$(word$, 1, POS(0) - startpos%) + MID$(word$, POS(0) - startpos% + 2)
END IF
PRINT MID$(word$, xx% - startpos% + 1);: LOCATE yy%, xx%
RETURN
END SUB

 
 Respond to this message   
 Copyright © 1999-2017 Network54. All rights reserved.   Terms of Use   Privacy Statement