How to enter a very long string:

by Solitaire (Login Solitaire1)
S

Use the INPUT$(1) function, together with conditions to test for a backspace, and exit when the user presses Enter. The default for INPUT$(1) does not show the cursor. That can be changed by using the third argument in the LOCATE command, which should be changed back to the default at the end of the block.

===================================================================
DIM row AS INTEGER, col AS INTEGER, charcount AS INTEGER
DIM P AS STRING, msg AS STRING
CLS
PRINT "Enter message below:"
charcount = 0
LOCATE , , 1   'This makes the cursor visible
DO
    row = CSRLIN
    col = POS(0)
    P$ = INPUT$(1)
    IF P$ = CHR$(13) THEN EXIT DO
    IF P$ <> CHR$(8) AND P$ <> CHR$(9) THEN
        PRINT P$;
        msg$ = msg$ + P$
        charcount = charcount + 1
    END IF
    IF P$ = CHR$(8) THEN
        charcount = charcount - 1
        msg$ = LEFT$(msg$, charcount)
        LOCATE row, col - 1
        PRINT " "
        LOCATE row, col - 1
    END IF
LOOP UNTIL P$ = CHR$(13)
LOCATE , , 0   'This restores the cursor to the default
PRINT : PRINT : PRINT "Your message is:"
PRINT msg$
PRINT : PRINT "It uses "; charcount; " characters."
SYSTEM



Posted on Jan 26, 2010, 12:00 PM

Respond to this message   

Return to Index


Response TitleAuthor and Date
* An INKEY$ loop can handle backspacing. INPUT$ throws in a fancy control character! on Jan 26
 I couldn't get INKEY$ to work past 255 characters.Solitaire on Jan 26
  You have to break up the lines on Jan 26
   * I think the INPUT$(1) technique is cleaner.Solitaire on Jan 26
    Well sooner or later QB gotta read it back and your's still needs to format it. on Jan 26