Re: Forgotten Statement

 BBS: Inland Empire Archive
Date: 05-09-92 (01:09)             Number: 185
From: TOM HAMMOND                  Refer#: NONE
  To: MICHAEL MALLEY                Recvd: NO  
Subj: Re: Forgotten Statement        Conf: (2) Quik_Bas
MM>  DO
MM>    KeyStroke$ = INKEY$
MM>  LOOP UNTIL LEN(KeyStroke$)
MM>  SELECT CASE ASC(KeyStroke$)
MM>    ...
MM>  END SELECT

MM>This will eliminate all string comparison, thus making everything much
MM>faster.  If you will be looking for extended characters (i.e. F1, Up
MM>arrow, etc...), first do a check on the length of KeyStroke$.  If it  is
MM>two, then make the comparison  SELECT CASE ASC(RIGHT$(KeyStroke$,1)).
MM>This will prove to be the most efficient.

Michael:

Forgive me for sticking my nose in here, but...

Just as a matter of preference, I like the way someone
(maybe Matt Hart, but can't recall) implemented it..

This has the added advantage of 'forcing' the ASCII value for
EXTENDED (2-byte) KEY CODES to be NEGATIVE, thus making them
easily identifiable later AND helping to eliminate the
ambiguity between ASC("M") = 77 and ASC(RIGHT$(KeyStroke$,1)) = 77
when KeyStroke$ = <RtArrow>.

GetKeyStroke:
  DO
    KeyStroke$ = INKEY$
  LOOP UNTIL LEN(KeyStroke$)

  If LEN(KeyStroke$) = 1 THEN
    a% = ASC(KeyStroke$)
  ELSE
    a% = -(RIGHT$(KeyStroke$,1))
  END IF

  SELECT CASE A
    CASE -75 '    <LtArrow>
      ...
    CASE -77 ' <RtArrow>
      ...
    CASE -71 ' <Home>
      ...
    CASE -79 ' <End>
      ...
    CASE -83 ' <Del>
      ...
    CASE 8 ' <BackSpace>
      ...
    CASE 32 TO 255 ' Alpha Keys
      ...
    CASE 13 ' <Enter>
      ...
    CASE ELSE
      GOTO GetKeyStroke
  END SELECT

Again, just personal preference.

Tom Hammond       N0SS


--- WM v2.00/91-0231
 * Origin: The Modem Zone BBS (314) 893-5106 (1:289/2)
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