Allen:
I ran into a side-note recently. I've used a character-parsing loop for years
like:
**----------------------------------------------------------------------------**
MenuExit = 0 ; ** initialize menu-exit variable
DecStr = NULL$ ; ** initialize decimal keypress
HexStr = NULL$ ; ** initialize hex keypress
KeyStr = NULL$ ; ** initialize ascii keypress
*
** Enter keypress capturing code
** U2 version block. This code simply waits for all keypress events and
** returns the ASCII, HEX, and DECIMAL value(s) of that keypress by
** testing for anything else existing in the Type-Ahead variable.
*LOOP ; ** UV
version
* AsciiChar = KEYIN() ; ** get ascii value UV
version
* DecChar = SEQ(AsciiChar) ; ** convert ascii to decimal UV
version
* DecStr := DecChar : SP1 ; ** build decimal keypress UV
version
* KeyStr := AsciiChar ; ** build ascii keypress UV
version
* HexStr := OCONV(AsciiChar, 'MX') ; ** hex value UV
version
* INPUT TA.FULL,-1 ; ** TAhead full? UV
version
*UNTIL NOT(TA.FULL) DO REPEAT ; ** UV
version
*
** This code will wait for proper input and if no keypress event occurs then
** if this is called from a menu then the screen timer variable (WaitTime) is
** processed and navigation is routed to the previous menu.
LOOP ; ** UD
version
IF NOT(WaitTime) THEN ; ** UD
version
INPUT AsciiChar,1: UNFILTERED ; ** get a raw byte UD
version
END ELSE ; ** UD
version
INPUT AsciiChar,1: FOR WaitTime UNFILTERED THEN ; ** UD
version
NULL ; ** UD
version
END ELSE ; ** UD
version
IF I.VALUE = NULL$ THEN I.VALUE = WCHAR ; ** UD
version
AsciiChar = CHAR(13) ; ** UD
version
MenuExit = 1 ; ** UD
version
END ; ** UD
version
END ; ** UD
version
DecChar = SEQ(AsciiChar) ; ** convert to decimal UD
version
HexStr := OCONV(AsciiChar, 'MX') ; ** convert to hex UD
version
DecStr := DecChar : SP1 ; ** build decimal string UD
version
KeyStr := AsciiChar ; ** build ascii UD
version
UNTIL NOT(SYSTEM(14)) DO REPEAT ; ** UD
version
*
** End of Include
**----------------------------------------------------------------------------**
>From within other BASIC code, where I want to manage data input, as opposed to
character input, I'd do something like:
**----------------------------------------------------------------------------**
ECHO OFF ; ** turn echo off to control output
DataInputStr$ = NULL$
LOOP
WaitTime = 0
INCLUDE DTABP,INCLUDES DATA.INPUT
...place some character test code here (e.g CR$ / LF$ / TAB$ / ESC$ / etc)
UNTIL LastHex = '0A' OR LastHex = '0D' DO
...place processing code here...
*
** Update the Data Input here (non screen-editor input)
DataInputStr$ := KeyStr
CRT KeyStr :
REPEAT
ECHO ON ; ** turn echo back on
**----------------------------------------------------------------------------**
In D3 we had no problem with this code. However, in UniData, we were having
some
problems with slow network connections, in that characters would seem to be
dropped
or merged within the character-processing loop. So I'm guessing UD's version
of this
process is a little less robust (but maybe not). I never tested the UV code to
see
if this this latency problem occured. Also, terminal types never made any
difference
because we'd define page and arrow keys in common like:
...in Include
NULL$ = ''
PgUpField = 15
PgDnField = 16
PageUpKey = TermInfoRec<PgUpField>
PageDownKey = TermInfoRec<PgDnField>
...in main program key processing loop we might do
IF DataInputStr$ = NULL$ THEN
IF KeyStr = PageUpKey THEN ...do something
IF KeyStr = PageDownKey THEN ...do something else
...etc...
END
Now it doesn't matter what terminal type people are using, as long as it's
defined at
login.
Bill
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:owner-u2-
>[EMAIL PROTECTED] On Behalf Of Allen Egerton
>Sent: Wednesday, April 30, 2008 2:32 AM
>To: [email protected]
>Subject: Re: [U2] Press any key to continue...
>
>Dennis Bartlett wrote:
><snip>
>> One way to beat this, and still allow you to use a single space as an exit
>> character, would be to create a loop that inputs a single character, then
>> tests if that character is a space. If so, exit the loop, if not, append
>> that character to the end of a string, eg
>>
>> InputtedValue = ''
>> Loop
>> Input Val,1:
>> if Val=' ' then exit
>> InputtedValue := Val
>> Repeat
><snip>
>
>This is correct, as is the rest of Dennis' post; but I'll add one
>caveat. When I've written this sort of loop, it's often been necessary
>to add a sleep or delay in the loop. Otherwise when this process is
>executing the computer can use the user's entire timeslice looping,
>'cause there's always something for the computer to do. Which will tend
>to bog the machine down for the other users, (much as a very intensive
>SELECT will do).
>
>Obviously this can also be dependent upon userload, hardware, operating
>system and Pick/U2 variant - some combinations work better than others.
>
>--
>Allen Egerton
>aegerton at pobox dot com
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/