BBS: Inland Empire Archive Date: 02-08-93 (17:35) Number: 305 From: VICTOR YIU Refer#: NONE To: ERIC MAYS Recvd: NO Subj: GETINPUT 1/2 Conf: (2) Quik_Bas
Here's what you're looking for!
-!!!!!!!!!!!!!!!!!!!!!!!!!!-8<-!!!!!-8<-!- snip here
' released into public domain
' +-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-+
' | GetInput.bas by Victor Yiu |
' | ~~~~~~~~~~~~ |
' | A full functioned replacement for INPUT. Includes |
' | full line editing: insert, typeover, delete, home/end, |
' | and next/previous word. Also lets you specify maximum |
' | line length, or let use input until end of line. |
' | The code is specially written for clarity and ease of |
' | understanding. All of the code is optimized to the max |
' | that I know how. |
' | In essence, it is just a full line editor. |
' | |
' | Syntax: |
' | In$ = GetInput$(Prompt$, MaxLen%) |
' | |
' | Prompt$ is the prompt that you want to be displayed when |
' | user is inputting data, like "Your name? " |
' | MaxLen is the maximum length that you will allow the |
' | user to type in. Use "0" or "-1" to input it |
' | to the end of the screen |
' +-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-+
' Declarations
DECLARE SUB Init ()
DECLARE SUB Alarm ()
DECLARE FUNCTION GetInput$ (Prompt$, MaxLen%)
DEFINT A-Z ' use integers by default for speed
COMMON SHARED Null$ ' set up some initial keys:
COMMON SHARED LeftK$, RightK$ ' it is faster and clearer to use variables
COMMON SHARED Home$, End$ ' (A$, B$) instead of constants ("d",
COMMON SHARED Insert$, Delete$' "xyz", CHR$(3))
COMMON SHARED CLeft$, CRight$ ' --> MY BENCHMARKS CONFIRM IT <--
COMMON SHARED SpaceBar$
CONST False = 0, True = NOT False ' set up boolean constants
Null$ = CHR$(0) ' define initial keys
SpaceBar$ = " "
Insert$ = Null$ + "R"
Delete$ = Null$ + "S"
LeftK$ = Null$ + "K": RightK$ = Null$ + "M"
Home$ = Null$ + "G": End$ = Null$ + "O"
CLeft$ = Null$ + "s": CRight$ = Null$ + "t"
CLS ' clear screen
COLOR 7, 0 ' use white on black
In$ = GetInput$("Enter a string: ", -1) ' input a string
PRINT
PRINT "You typed ["; In$; "]"
' +-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-+
' | Alarm by Victor Yiu |
' | ~~~~~ |
' | Plays a tune |
' +-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-+
SUB Alarm
SOUND 1000, .1
END SUB
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$ <> ""
>>>>> Continued on next message...
--- Blue Wave/RA v2.10 [NR]
* Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690 / (1:106/30.0)

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