GetInput 1/3

 BBS: Inland Empire Archive
Date: 01-03-93 (00:21)             Number: 346
From: VICTOR YIU                   Refer#: NONE
  To: IMRAN HAYAT                   Recvd: NO  
Subj: GetInput     1/3               Conf: (2) Quik_Bas
 -=> Quoting David Wang to Imran Hayat <=-

 IH> Another little question!  In QBasic, how can you limit the
 IH> amount that the cursor can travel in an INPUT statement? In

Here's what you are looking for.  Maybe just a little OVERdone...
It is an excellent replacement!

----------------------------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

>>>>>>>>---------- continued on next message...

... Restroom meter:  [......../]  Aaarhgh.  I've got to go!!!
--- Blue Wave/RA v2.10 [NR]
 * Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690
/ RA 1.11 / (1:106/30.0)
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