**Need Help with User INPUT, ASCII Codes, INPUT String length 
Author Message
 **Need Help with User INPUT, ASCII Codes, INPUT String length

        I am attempting to learn the BASICS of Q-basic, and have a few
questions that I have been unable to find answers to.......

1) How can I get user input, other than by using the INPUT statement ?

     ( I don't like the ? that follows INPUT)
      Can individual keystrokes be detected? If so , how? By  ASCII

      codes??

2) Where can I get a chart of all of the ASCII codes ?

3) How can I limit the length of user input ? I would like to limit
the length of the user's INPUT to 8 characters.......Is this possible?

        Any help will be greatly appreciated.......Thanx,
                                                Wayne



Fri, 25 Aug 2000 03:00:00 GMT  
 **Need Help with User INPUT, ASCII Codes, INPUT String length

Quote:

>    I am attempting to learn the BASICS of Q-basic, and have a few
> questions that I have been unable to find answers to.......

> 1) How can I get user input, other than by using the INPUT statement ?
>      ( I don't like the ? that follows INPUT)

QBasic has a 'Help' function.  This is clipped from the help for INPUT:

  INPUT reads input from the keyboard or a file. LINE INPUT reads a line
  of up to 255 characters from the keyboard or a file.

  INPUT [;] ["prompt"{; | ,}] variablelist

    _ prompt      An optional literal string that is displayed before
                  the user enters data. A semicolon after prompt appends
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                  a question mark to the prompt string.
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Quote:
> Can individual keystrokes be detected? If so , how? By  ASCII codes??

See help on INKEY$, INPUT$, CHR$ and ASC.

Quote:
> 2) Where can I get a chart of all of the ASCII codes ?

From help, go to 'Contents' and click on 'ASCII Character Codes'.

Quote:
> 3) How can I limit the length of user input ? I would like to limit
> the length of the user's INPUT to 8 characters.......Is this possible?

By using INKEY$ or INPUT$ and programming the logic for the interface.
As keys are pressed, store them in a string.  When backspace is pressed
remove a character.  Limit the input to whatever you want to allow.

Download Ethan Winer's free BASIC tutorial and study it.
  http://www.ethanwiner.com/WINER.ZIP
--
Judson McClendon          This is a faithful saying and worthy of all
Sun Valley Systems        acceptance, that Christ Jesus came into the

(please remove zzz from email id to respond)



Fri, 25 Aug 2000 03:00:00 GMT  
 **Need Help with User INPUT, ASCII Codes, INPUT String length

Quote:

>         I am attempting to learn the BASICS of Q-basic, and have a few
> questions that I have been unable to find answers to.......

> 1) How can I get user input, other than by using the INPUT statement ?

>      ( I don't like the ? that follows INPUT)
>       Can individual keystrokes be detected? If so , how? By  ASCII

Instead of typing INPUT "Question";question$You can type INPUT
"Question",question$
By changing the ; (semicolon) to a (colon) you won't get the ?

Quote:

>       codes??

To detect keystrokes you can use INKEY$This simple program will detect if
A is pressed and then print "YOU DID IT" on the screen

DO
  X$=INKEY$
  IF X$="A" or X$="a" THEN
    PRINT "YOU DID IT":END
  END IF
LOOP

Quote:
> 2) Where can I get a chart of all of the ASCII codes ?

In the help function you'll be able to find a chart of all ASCII codes

Quote:
> 3) How can I limit the length of user input ? I would like to limit
> the length of the user's INPUT to 8 characters.......Is this possible?

An easy way to do it is by using INPUT and then take the 8 first
charactersin the string:

INPUT "Question: ",question$
question$=LEFT$(question$,8)

Quote:
>         Any help will be greatly appreciated.......Thanx,
>                                                 Wayne



Sat, 26 Aug 2000 03:00:00 GMT  
 **Need Help with User INPUT, ASCII Codes, INPUT String length

Quote:

>         I am attempting to learn the BASICS of Q-basic, and have a few
> questions that I have been unable to find answers to.......

> 1) How can I get user input, other than by using the INPUT statement ?

>      ( I don't like the ? that follows INPUT)
>       Can individual keystrokes be detected? If so , how? By  ASCII

>       codes??

It can be done, but your reason is a bad reason. INPUT will not put the
question mark if you put input "test", test$ instead of input "test";
test$ (change the semicolon to a comma).
Quote:

> 2) Where can I get a chart of all of the ASCII codes ?

QB help! Get help on CHR$ or ASC and there's a link to the character
codes.
Quote:

> 3) How can I limit the length of user input ? I would like to limit
> the length of the user's INPUT to 8 characters.......Is this possible?

This example understands enter, backspace, and nicely works with the
input underscore. It does NOT work with arrows. It will try to display
any characters other than the trapped ones (backspace, enter, etc...)
including a beep (ctrl-g).

dr$ = ""
do
inke$ = inkey$
if inke$ <> "" then
        if inke$ = chr$(13) then
                exit do
        elseif inke$ = chr$(8) then
                dr$ = left$(dr$, len(dr$) - 1)
        elseif len(dr$) => 8 then
                beep
        else
                dr$ = dr$ + inke$
        end if
end if
locate 1, 1
if Timer > T then
        if ul$ = "_" then
                ul$=" "
        else
                ul$="_"
        end if
        T = Timer + .2
end if
print "8 Characters: " + dr$ + ul$
loop

Quote:

>         Any help will be greatly appreciated.......Thanx,
>                                                 Wayne

--
-Mike Dombrowski
-Mike's Software
-http://surf.to/miked.3068/
-http://surf.to/miked.dell.2578/


Sun, 27 Aug 2000 03:00:00 GMT  
 **Need Help with User INPUT, ASCII Codes, INPUT String length

Quote:

>>        I am attempting to learn the BASICS of Q-basic, and have a few
>>questions that I have been unable to find answers to.......

>>1) How can I get user input, other than by using the INPUT statement ?

>>     ( I don't like the ? that follows INPUT)
>>      Can individual keystrokes be detected? If so , how? By  ASCII

>>      codes??

To do it right, you'll need to write your own routine (see below).

Quote:
>>2) Where can I get a chart of all of the ASCII codes ?

Look in the QBASIC help.

Quote:
>>3) How can I limit the length of user input ? I would like to limit
>>the length of the user's INPUT to 8 characters.......Is this possible?

>>        Any help will be greatly appreciated.......Thanx,
>>                                                Wayne

Check this out; it's a little bit beyond just the basics, but it's
about as simple as this type of routine gets, and still retain any
error-checking. Make sure you unwrap the longer lines that my
newsreader wrapped.

' INPUTS.BAS  5-1-95  Matt Hart
' Insert mode bug fix, delete key and word-left/right handlers
' by Len Philpot, 5/6/95
'
' A generic input routine using INKEY$
' Use this instead of INPUT or LINE INPUT.
' This will avoid Ctrl-Breaking out of a
' program, as well as provide greater control
' during input.

DEFINT A-Z

CONST FALSE = 0, TRUE = NOT FALSE

DECLARE SUB InputField (E$, ERow%, ECol%, ELen%, Fg%, Bg%, Hfg%,
Hbg%, KeyPress%)

   CLS
   READ NumInput

   REDIM Rows(1 TO NumInput), Cols(1 TO NumInput), Lens(1 TO
NumInput)
   REDIM Da$(1 TO NumInput)

   FOR i = 1 TO NumInput
      READ Rows(i), Cols(i), Lens(i)
      LOCATE Rows(i), Cols(i) - 8: PRINT "Num"; i; ":"
   NEXT

   Fg = 7: Bg = 0
   Hfg = 0: Hbg = 7
   Fld = 1

   DO
      CALL InputField(Da$(Fld), Rows(Fld), Cols(Fld), Lens(Fld), Fg,
Bg, Hfg, Hbg, KeyPress)
      SELECT CASE KeyPress
         CASE 27        ' Escape
            EXIT DO
         CASE 13, 9, -80' Enter, Tab, Dn Arrow
            Fld = Fld + 1: IF Fld > NumInput THEN Fld = 1
         CASE -15, -72  ' Shift Tab, Up Arrow
            Fld = Fld - 1: IF Fld < 1 THEN Fld = NumInput
      END SELECT
   LOOP
   END
   DATA 3
   DATA 10,10,10
   DATA 11,10,1
   DATA 12,10,20

SUB InputField (E$, ERow, ECol, ELen, Fg, Bg, Hfg, Hbg, KeyPress)

   Insrt = TRUE
   CPos = 0
   COLOR Hfg, Hbg

   DO
      LOCATE ERow, ECol: PRINT SPACE$(ELen);
      IF Insrt THEN
         LOCATE ERow, ECol, 1, 14, 15
      ELSE
         LOCATE ERow, ECol, 1, 7, 15
      END IF
      PRINT E$;
      LOCATE ERow, ECol + CPos

      DO: A$ = INKEY$: LOOP UNTIL LEN(A$)
      LOCATE , , 0
      KeyPress = ASC(RIGHT$(A$, 1))
      IF LEN(A$) = 2 THEN KeyPress = -KeyPress

      SELECT CASE KeyPress
         CASE 27, 13, 9: EXIT DO    ' Escape, Enter, Tab
         CASE -71                   ' Home
            CPos = 0
         CASE -79                   ' End
            CPos = LEN(E$)
         CASE -82                   ' Insert
            Insrt = NOT Insrt
         CASE -75                   ' Left Arrow
            IF CPos THEN CPos = CPos - 1
         CASE -77                   ' Right Arrow
            IF CPos < ELen AND CPos < LEN(E$) THEN CPos = CPos + 1
         CASE -83                   ' Del (added 5/6/95 - Len
Philpot)
            IF LEN(E$) > 0 THEN E$ = LEFT$(E$, CPos) + MID$(E$, CPos
+ 2)
         CASE -115                  ' Ctrl-left
            IF CPos THEN            ' (added 5/7/95 - Len Philpot)
               X = CPos - 1         ' Jump to the previous word or
               DO                   ' the start of E$, whichever
                  X = X - 1         ' is closer
                  IF X < 1 THEN EXIT DO
                  PrvWord = (MID$(E$, X, 1) = " ") AND (ASC(MID$(E$,
X + 1, 1)) > 32)
               LOOP UNTIL PrvWord OR X <= 1
               IF PrvWord AND (X > 0) THEN CPos = X ELSE CPos = 0
            END IF
         CASE -116                  ' Ctrl-right
            IF CPos < LEN(E$) THEN  ' (added 5/7/95 - Len Philpot)
               X = CPos + 1         ' Jump to the next word or the
               DO                   ' end of E$, whichever is closer
                  NxtWord = INSTR(X, E$, " ")
                  X = NxtWord + 1
               LOOP UNTIL ASC(MID$(E$, X, 1)) > 32
               IF NxtWord > CPos THEN CPos = NxtWord ELSE CPos =
LEN(E$)
            END IF
         CASE IS < 0: EXIT DO       ' Other scan codes
         CASE 8                     ' Backspace
            IF CPos THEN
                E$ = LEFT$(E$, CPos - 1) + MID$(E$, CPos + 1)
                CPos = CPos - 1
            END IF
         CASE 32 TO 127             ' Character keys
            IF CPos = ELen THEN
               MID$(E$, ELen, 1) = A$
            ELSE
               IF Insrt THEN
'This IF..THEN was added to correct a bug that enabled the edit
field
'to grow in length when in insert mode and the cursor was not at the
'end of the field, 5/6/95 - Len Philpot
                  IF LEN(E$) < ELen THEN
                     E$ = LEFT$(E$, CPos) + A$ + MID$(E$, CPos + 1)
                     CPos = CPos + 1
                  END IF
               ELSE
                  CPos = CPos + 1
                  IF LEN(E$) < CPos THEN E$ = E$ + " "
                  MID$(E$, CPos, 1) = A$
               END IF
            END IF
      END SELECT
   LOOP

   COLOR Fg, Bg
   LOCATE ERow, ECol: PRINT SPACE$(ELen);
   LOCATE ERow, ECol: PRINT E$;

END SUB





Mon, 28 Aug 2000 03:00:00 GMT  
 **Need Help with User INPUT, ASCII Codes, INPUT String length


Quote:

>This example understands enter, backspace, and nicely works with the
>input underscore. It does NOT work with arrows. It will try to display
>any characters other than the trapped ones (backspace, enter, etc...)
>including a beep (ctrl-g).


today.

CLS
DO
    KeyPress% = INP(&H60)          'This reads the keyboard
    LOCATE 5, 20
    PRINT KeyPress%

    A$ = INKEY$             'These two lines empty the Key Buffer
    A$ = ""                 'and stop the beeps. Try the prog without
                            'and see what happens!

SELECT CASE A%
    CASE 75                 'Hard to remember what the numbers are
        PRINT "You pressed the Left Arrow "

                etc.........

--
//Peter Aksberg

WWW: http://www.algonet.se/~diver1
UIN: 536032



Mon, 28 Aug 2000 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Using ascii codes to validate html form input

2. code similar to Qbasic INPUT and LINE INPUT keywords

3. vba user input help needed

4. Need Help-Validating user input

5. input box code help needed

6. evaluating a string inputted by user

7. Help: INPUT / INPUT # for gopher/UNIX files

8. ?? code for PARSING input string for SQL query

9. ?? code for PARSING input string for SQL query

10. waiting for the users input - stop and start code-processing using events

11. VB code and script input needed....

12. Need Some Input With This Source Code

 

 
Powered by phpBB® Forum Software