Qbasicnews.com
November 12, 2019, 06:19:23 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: how to get a shift+tab into the program?  (Read 4591 times)
moosecode
New Member

Posts: 5


« on: January 28, 2003, 12:14:22 PM »

I am entering data in a form in QB, and I want to allow the user to use shift + tab to go back to the previous field if needed.

Will it work to run a routine where it takes the inkey$ and if it's not a letter, put it into a temp$ and then add the 2nd inkey$ to it?

or am i over-complicating this?

I can make the inputs tab through the available fields, but I would like to be able to reverse if needed.


I tried gettting a multi-key.bas program online, but the one I got has call absolute(0) line that renders "sub-program not defined" error, which I don't understand how to resolve.

I don't need to have alt or control options available, everything else is done using function keys and menus.

(note: I did modify some code I found under the topic limiting the input$ length, so if that is your code I used, I appreciate your insight - I forget who posted the particular solution idea.)


CLS
PRINT "EDIT CUSTOMER: "
LOCATE 3, 1: COLOR 7, 0
PRINT "FIRST NAME: "
LOCATE 5, 1: COLOR 7, 0
PRINT "LAST NAME: "
LOCATE 7, 1: COLOR 7, 0
PRINT "PHONE #:      (***) ***-****"
LOCATE 9, 1: COLOR 7, 0
PRINT "ALT. PHONE #: (***) ***-****"

add.name:
   
   MaxLength% = 15
   MyString$ = ""
   finished% = 0
   cursor$ = " "
   x% = 3
   y% = 15
   LOCATE x%, y%: PRINT ">"
   WHILE NOT finished%
      LOCATE x%, y% + 1: PRINT cursor$   ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.last.name
           
     END SELECT
   WEND

add.last.name:
 
   MaxLength% = 15
   MyString$ = ""
   finished% = 0
   cursor$ = " "
   x% = 5
   y% = 15
   LOCATE x%, y%: PRINT ">"
   WHILE NOT finished%
      LOCATE x%, y% + 1: PRINT cursor$    ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
       
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.area1
         
     END SELECT
   WEND


add.area1:

 
   MaxLength% = 3
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 7
   y% = 16
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
       
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.pre1
         
     END SELECT
   WEND
add.pre1:

   MaxLength% = 3
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 7
   y% = 21
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
     
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.last4
       
     END SELECT
   WEND
add.last4:


   MaxLength% = 4
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 7
   y% = 25
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
     
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.area2
       
     END SELECT
   WEND

add.area2:

   MaxLength% = 3
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 9
   y% = 16
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
     
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.pre2
       
     END SELECT
   WEND
add.pre2:
 
   MaxLength% = 3
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 9
   y% = 21
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
     
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO add.alt.last4
       
     END SELECT
   WEND
add.alt.last4:

   MaxLength% = 4
   MyString$ = ""
   finished% = 0
   cursor$ = "_"
   x% = 9
   y% = 25
   WHILE NOT finished%
      LOCATE x%, y%: PRINT cursor$     ' Cursor :)
      k$ = INKEY$
      IF k$ <> "" THEN k% = ASC(k$) ELSE k% = 0
      SELECT CASE k%
         CASE 13:     ' This one is ENTER key
            finished% = -1    ' End!
         CASE 9:
            finished% = -1 'end of this sequence
     
         CASE 8:       ' This one is Backspace key
            IF MyString$ <> "" THEN  ' Only if there is something to delete
               LOCATE x%, y%: PRINT " " ' delete cursor
               y% = y% - 1
               MyString$ = LEFT$(MyString$, LEN(MyString$) - 1)' We delete the last char
            END IF
         CASE IS >= 32:        ' From Space to infinite (letters/numbers...)
            IF LEN(MyString$) < MaxLength% THEN   ' <- Key!!
               LOCATE x%, y%: PRINT k$
               y% = y% + 1
               MyString$ = MyString$ + k$
            END IF

            IF LEN(MyString$) = MaxLength% THEN GOTO leaving
       
     END SELECT
   WEND

leaving:
LOCATE 13, 15
PRINT "this is the end"
SYSTEM
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: January 28, 2003, 12:53:21 PM »

I'd just use backspace or something that's one key press.
Remember, KISS...

 :rotfl:

CLS
DO
I$ = INKEY$
IF I$ <> "" THEN
FOR I% = 1 TO 2
IF LEN(I$) >= I% THEN
LOCATE I%, 1: PRINT ASC(MID$(I$, I%, 1))
ELSE
LOCATE I%, 1: PRINT SPACE$(3)
END IF
NEXT I%
IF I$ = CHR$(27) THEN EXIT DO
END IF
LOOP

SHIFT = CHR$(9)
SHIFT+TAB = chr$(0)+CHR$(15)
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
moosecode
New Member

Posts: 5


« Reply #2 on: January 28, 2003, 01:12:02 PM »

I think I 've decided to do a forward tab only, then offer the user a menu choice at the end to go back and edit the fields.

in the program, each data entry can be saved in an array and to the storage file, so I can store the values for that record, and if nothing changes then nothing gets lost.
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #3 on: January 28, 2003, 01:20:20 PM »

is resolved by putting /L on QB's command-line (and making sure that the file QB.QLB is somewhere where QB.EXE can find it).  Shift-tab is the two-byte string CHR$(0)+CHR$(15).  In other words, if A$ is the return from INKEY$ (e.g., A$ = INKEY$),

ASC(LEFT$(A$,1))

will be 0 and

ASC(RIGHT$(A$,1))

will be 15.
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #4 on: January 29, 2003, 12:34:54 AM »

If you want editable TAB based Fields here:

http://relsoft.wrq.cjb.net//files/Address.bas

 :rotfl:
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
moosecode
New Member

Posts: 5


« Reply #5 on: January 29, 2003, 08:18:12 AM »

Thanks for the help everyone.  That problem has been resolved.


-----
Shift-tab is the two-byte string CHR$(0)+CHR$(15). In other words, if A$ is the return from INKEY$ (e.g., A$ = INKEY$),
ASC(LEFT$(A$,1)) will be 0 and
ASC(RIGHT$(A$,1)) will be 15.
-------

SO if I did something like

k$=inkey$
if k$ = chr$(0) then let cmd$ = k$
k$=inkey$
let k$ = k$ + cmd$
if k$ = chr$(0) + chr$(15) then goto previous.field
else goto next.section

would that syntax work? or is it making it more complicated?
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #6 on: January 29, 2003, 08:30:53 AM »

Try:

If Len(K$)>1 then
    'Process Extended code
   'ie Right$(K$,1)
Else
   'process normal keypress
end if
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #7 on: January 29, 2003, 02:00:57 PM »

You were only testing the first byte in K$.  Your test will pass for any keystroke involving a zero ascii code (and there are a great many of those, such as ALT key sequences).  Also, when you assign K$ to the return from INKEY$, put it in a loop, e.g.,

K$ = ""
WHILE K$ = ""
K$ = INKEY$
WEND

Otherwise, you'll likely miss the opportunity to press a key.  (INKEY$ doesn't pause program execution, waiting for the keypress.)
Logged

ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!