Qbasicnews.com
how to get a shift+tab into the program? - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: how to get a shift+tab into the program? (/thread-103.html)



how to get a shift+tab into the program? - moosecode - 01-28-2003

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


agamemnus - Agamemnus - 01-28-2003

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)


KISS - moosecode - 01-28-2003

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.


The "Subprogram not defined" error... - Glenn - 01-28-2003

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.


how to get a shift+tab into the program? - relsoft - 01-29-2003

If you want editable TAB based Fields here:

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

:rotfl:


how to get a shift+tab into the program? - moosecode - 01-29-2003

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?


how to get a shift+tab into the program? - relsoft - 01-29-2003

Try:

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


See relsoft's answer... - Glenn - 01-29-2003

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.)