🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.lang.basic
Article #418

Re: Time restriction on data entry

#418
From: David Steffen
Date: Thu, 07 Jan 1993 23:16
68 lines
2962 bytes
jr2921r@acad.drake.edu () writes:
>I am writing a short program in QuickBasic 4.5 which requires the user to 
>input an answer to a question.  However, I only want to give the user a few
>seconds to perform the data entry.  Is there an easy way to do this using
>the INPUT statement?

hutch@bellman.lanl.gov writes:
>I don't believe you can use INPUT for this as it ties up the system until the
>user presses Return.
>
>Rather, I think you would have to write a routine for scanning the keyboard
>inside your timer loop, exiting when a keystroke is detected.  This would
>work fine for single character replies, but not if the user had to type in
>multiple characters.
>
>Any other ideas from someon else?

I have never done precisely this, but frequently I need to accept
input while doing something else at the same time.  For this purpose,
the INKEY$ function of the Microsoft BASICs is the answer.  INKEY$
returns immediately, with the null string if nothing was typed, or
with the character typed.  Thus, just collect characters with INKEY$
until your time is up.  How you monitor the time is, I think, machine
dependent.  In a pinch, I suppose you could even substitute a FOR/NEXT
loop for the WHILE/WEND loop I describe below, hand calibrating the
number of passes through the loop to give the desired time.

This gets more or less complex, of course, depending on what you are
inputting, and if you want to allow editing (e.g. backspace).  In the
example below, I have assumed that you want to input a carriage return
delimited string, and that no editing is allowed.  (Editing is machine
specific, as it requires knowing the codes for removing characters and
backspacing on the screen - commonly <backspace - space - backspace>.)

Example code below:

FALSE% = 0: TRUE% = NOT FALSE%

finished% = FALSE%
buffer$ = ""
WHILE NOT finished%
        Temp$ = INKEY$
        IF Temp$ = CHR$(13) THEN
           finished% = TRUE%
        ELSE
	   buffer$ = buffer$ + INKEY$
        END IF
        {check the time}
        IF {you are out of time} THEN finished% = TRUE%
WEND

End Example Code:

I have not tested above code itself - it is derived from memory of
routines I have done like this (on the MAC - which shouldn't matter).
Use at your own risk.

Hope this is of some help.




-- 
David Steffen
Department of Cell Biology, Baylor College of Medicine, Houston TX 77030
Telephone = (713) 798-6655, FAX = (713) 790-0545
Internet = steffen@bcm.tmc.edu
Technical Details
Message-ID: <1iidkdINNcf7@gazette.bcm.tmc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!bcm!bcm!usenet
References: <1993Jan7.091656.1@acad.drake.edu> <1993Jan7.212543.8012@newshost.lanl.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!bcm!bcm!usenet
From: steffen@mbcr.bcm.tmc.edu (David Steffen)
Newsgroups: alt.lang.basic
Subject: Re: Time restriction on data entry
Date: 7 Jan 1993 23:16:29 GMT
Organization: Baylor College of Medicine, Houston, Tx
Lines: 68
Message-ID: <1iidkdINNcf7@gazette.bcm.tmc.edu>
References: <1993Jan7.091656.1@acad.drake.edu> <1993Jan7.212543.8012@newshost.lanl.gov>
NNTP-Posting-Host: mbcr.bcm.tmc.edu