LIMITING THE LENGTH OF IN

``` BBS: Inland Empire Archive
Date: 02-12-93 (05:00)             Number: 339
From: ROB MCKEE                    Refer#: NONE
To: RUSTY GORDON                  Recvd: NO
Subj: LIMITING THE LENGTH OF IN      Conf: (2) Quik_Bas```
```Hello Rusty!
You wrote in a message to All:

RG> This may sound like a stupid question but I have 8
RG> Quickbasic books and cannot find the answer.
RG> I understand how to limit the size of a string using
RG> DIM variable\$ as string * 15 etc... but how do I put a limit
RG> to the  number of characters the user can enter as in the
RG> sample below:

RG> Enter Feature Name 北北北北北北北.

-------------------------8<--------------------------------
DECLARE FUNCTION GINPUT\$ (MaxLen%,Fill%)
' ? GINPUT\$(44,176) ' Example of Usage
' END

FUNCTION GINPUT\$ (MaxLen%, Fill%)
Fill\$= CHR\$(Fill%)
r = CSRLIN
c = POS(0)
PRINT STRING\$(MaxLen%,Fill\$);
LOCATE r, c, 1, 6, 7
DO
PRINT "";
DO
i\$ = INKEY\$
LOOP WHILE i\$ = ""
SELECT CASE i\$
CASE " " TO "z"
IF LEN(Worki\$) < MaxLen% THEN
Worki\$ = Worki\$ + i\$
PRINT i\$;
END IF
CASE CHR\$(8)
IF LEN(Worki\$) = 1 THEN
Worki\$ = ""
LOCATE r, c, 0
PRINT STRING\$(MaxLen%,Fill\$);
LOCATE r, c, 1, 6, 7
ELSEIF LEN(Worki\$) > 1 THEN
Worki\$ = LEFT\$(Worki\$, LEN(Worki\$) - 1)
PRINT CHR\$(29); Fill\$; CHR\$(29);
END IF
CASE CHR\$(0) + "w"  ' Control-Home Erase Line
Worki\$ = ""
LOCATE r, c, 0
PRINT STRING\$(MaxLen%,Fill\$);
LOCATE r, c, 1, 6, 7
CASE CHR\$(10), CHR\$(13)  ' Line Feed or Return Exit
with String          EXIT DO
CASE CHR\$(27)
GBQuitAction = True   ' A Shared Variable for
Exiting Program          EXIT FUNCTION         ' You don't
Have to use it (True=-1 and     END SELECT
' is a CONST False = 0, True = NOT False)  LOOP
GINPUT\$ = Worki\$
END FUNCTION
-------------------------8<--------------------------------

Catcha Later , I'll see you on the flip side - Rob

--- timEd/B6
* Origin: Another Quik_Bas Point in Richmond, CA (1:125/411)
```

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