Input Routine

 BBS: Inland Empire Archive
Date: 12-31-92 (07:53)             Number: 386
From: TOM HAMMOND                  Refer#: NONE
  To: IMRAN HAYAT                   Recvd: NO  
Subj: Input Routine                  Conf: (2) Quik_Bas
IH>In QBasic, how can you limit the amount that the cursor can travel in
   an INPUT statement?

What you have to do is to not use INPUT but build yourself an input
routine which takes each character as it is entered and appends it to
the end of a string which it builds as characters are entered.  Then,
you can (with each subsequent entry) check the length of the input
string (the one you're building) and just not allow further input when
the maximum field length has been met.

Here's an input routine which was posted a while back by Margaret Romao.
It may help you get started.  I have at least two other input routines
but both are MUCH longer (15k and 50k respectively) than this one.  They
would take several messages to post.  Will consider seinding them if you
REALLY need them, but please try this one first.  I'm sure you'll get
suggestions from other users too.  Good Luck

Tom Hammond

'Date: 02-18-92 (10:54)             Number: 6260
'From: MARGARET ROMAO               Refer#: NONE
'Subj: Input replacement              Conf: (13) QuickBasic
'
-----
'I saw a request for the following information, so here's an input 'replacement. The VAL function may be used to convert the variable Inp$ 'to a numeric value. Sorry about the GOTO's. DECLARE SUB Parser (Inp$, Prompt$, Row%, Col%, Length%, Fore%, Back%) ' A little sample code to show how to call the procedure COLOR 15, 1: CLS Parser Inp$, "Enter some text: ", 4, 4, 8, 15, 1 LOCATE 6, 4: PRINT "You entered: "; Inp$ SUB Parser (Inp$, Prompt$, Row%, Col%, Length%, Fore%, Back%) CPos% = LEN(Inp$) InpLength% = LEN(Inp$) COLOR Fore%, Back% LOCATE Row%, Col%, 1, 10, 11: PRINT Prompt$; GN1: DO: InKy$ = INKEY$: LOOP UNTIL LEN(InKy$) IF LEN(InKy$) = 1 THEN SELECT CASE ASC(InKy$) CASE 32 TO 126 ' std. alphanumeric keys IF InpLength% < Length% THEN temp1$ = LEFT$(Inp$, CPos%) temp2$ = RIGHT$(Inp$, InpLength% - CPos%) Inp$ = temp1$ + InKy$ + temp2$ InpLength% = InpLength% + 1 CPos% = CPos% + 1 LOCATE Row%, (Col% + LEN(Prompt$)) PRINT Inp$ LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% GOTO GN1 END IF CASE 8 'Backspace key IF InpLength% > 0 AND CPos% > 0 THEN temp1$ = LEFT$(Inp$, CPos% - 1) temp2$ = RIGHT$(Inp$, InpLength% - CPos%) Inp$ = temp1$ + temp2$ InpLength% = InpLength% - 1 CPos% = CPos% - 1 LOCATE Row%, (Col% + LEN(Prompt$)) PRINT Inp$ + CHR$(32) LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% END IF CASE 13 ' <C/R> GOTO GNE CASE ELSE SOUND 50, 3 GOTO GN1 END SELECT ELSE InKy$ = (RIGHT$(InKy$, 1)) SELECT CASE ASC(InKy$) CASE 75 'right arrow IF CPos% > 0 THEN CPos% = CPos% - 1 LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% GOTO GN1 END IF CASE 77 'left arrow IF CPos% < InpLength% THEN CPos% = CPos% + 1 LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% GOTO GN1 END IF CASE 71 'home key CPos% = 0 LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% CASE 79 'end key CPos% = InpLength% LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% CASE 83 'del key IF InpLength% > 0 AND CPos% < InpLength% THEN temp1$ = LEFT$(Inp$, CPos%) temp2$ = RIGHT$(Inp$, InpLength% - CPos% - 1) Inp$ = temp1$ + temp2$ InpLength% = InpLength% - 1 LOCATE Row%, (Col% + LEN(Prompt$)) PRINT Inp$ + CHR$(32) LOCATE Row%, (Col% + LEN(Prompt$)) + CPos% END IF CASE ELSE SOUND 50, 3 GOTO GN1 END SELECT END IF IF InpLength% >= Length% THEN IF Length% < 1 THEN GOTO GN1 SOUND 800, 1 GOTO GN1 END IF GOTO GN1 GNE: LOCATE Row%, (Col% + LEN(Prompt$)), 0 END SUB THE END! --- * Origin: Night Shift BBS (314)635-7588 HST 14.4 (1:289/15)
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