QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: bartok on June 11, 2021, 02:42:41 am

Title: How to leave an input line.
Post by: bartok on June 11, 2021, 02:42:41 am
I have a problem. My program (I have attached an image as example) is almost finished, but at the moment is a flow. I have to introduce the possibility to navigate through it and then write the results to files.

The problem is this.
The program at the start asks some input:

1) Enter input 1:      B
2) Enter input 2:      B
3) Enter input 3:      C
4) Enter input 4:      _


Suppose that the program is now asking input 4 and that we have just realized that input 1 is wrong, because is not B, but A.

I want to do this: just pressing up arrow (without enter), the program must leaves the input line corresponding to input 4 and go up, to line asking input 3, and so on (possibly preserving input 2 and 3).
Title: Re: How to leave an input line.
Post by: euklides on June 11, 2021, 05:39:17 am

Not very elegant, but for example you could imagine something like that:


1000 Input "blabla A (or -1 to cancel)", a1$: If a1$ = "-1" Then Stop
1001 Input "blabla B (or -1 -> asking A)", b1$: If b1$ = "-1" Then GoTo 1000
1002 Input "blabla C (or -1 -> asking B)", c1$: If c1$ = "-1" Then GoTo 1001
1003 Input "blabla D (or -1 -> asking C)", d1$: If d1$ = "-1" Then GoTo 1002
Title: Re: How to leave an input line.
Post by: bplus on June 11, 2021, 09:28:42 am
EDIT missed this part:
Quote
I want to do this: just pressing up arrow (without enter), the program must leaves the input line corresponding to input 4 and go up, to line asking input 3, and so on (possibly preserving input 2 and 3).
Title: Re: How to leave an input line.
Post by: bplus on June 11, 2021, 11:36:33 am
EDIT missed this part:
Quote
I want to do this: just pressing up arrow (without enter), the program must leaves the input line corresponding to input 4 and go up, to line asking input 3, and so on (possibly preserving input 2 and 3).
Title: Re: How to leave an input line.
Post by: bplus on June 11, 2021, 11:54:21 am
EDIT missed this part:
Quote
I want to do this: just pressing up arrow (without enter), the program must leaves the input line corresponding to input 4 and go up, to line asking input 3, and so on (possibly preserving input 2 and 3).
Title: Re: How to leave an input line.
Post by: SMcNeill on June 11, 2021, 12:57:07 pm
Terry Ritchie’s GLInput Library does what you’re looking for, and is well documented, if you have a copy of it.
Title: Re: How to leave an input line.
Post by: NOVARSEG on June 11, 2021, 09:58:52 pm
@bartok


Here is a basic program that shows what you want. It takes a lot more coding to make it work properly.


Code: QB64: [Select]
  1. DIM msg(1) AS STRING
  2.  
  3. msg(0) = "Enter name "
  4. msg(1) = "Enter date "
  5.  
  6. LL1:
  7. FOR X = 0 TO 1
  8.     IF INKEY$ = CHR$(27) THEN END
  9.     LOCATE 10 + X, 2 + LEN(msg(X)): PRINT SPACE$(10)
  10.     LOCATE 10 + X, 2: PRINT msg(X);: INPUT S(X)
  11.  
  12.  
  13.     i$ = INKEY$
  14.     IF i$ = CHR$(27) THEN END
  15.     IF i$ = CHR$(13) THEN GOTO LL1
  16.  

Title: Re: How to leave an input line.
Post by: Cobalt on June 11, 2021, 10:23:10 pm
A custom input routine would probably be your best bet for that kind of flexibility.
Based around a DO:LOOP structure without GOTO. It will take me a bit to write you up an example but if your willing to wait.....
Title: Re: How to leave an input line.
Post by: Cobalt on June 11, 2021, 11:59:49 pm
Not super refined but is something like this what you want?

Code: QB64: [Select]
  1. 'Editable input example
  2. 'lets start with some base constants
  3. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  4. CONST TRUE = -1, FALSE = NOT TRUE
  5.  
  6. DIM Inputs(10) AS STRING 'for this example we will allow up to 10 inputs
  7.  
  8. 'some prep work
  9. Opt%% = 1 'start on the first input line
  10.  
  11. 'start our loop up
  12.  KBD& = _KEYHIT 'keyboard input
  13.  IF KBD& < 0 THEN KBD& = 0 'negate any negative keyhit values
  14.  FOR I%% = 1 TO 10 'loop through all our input options
  15.   'double space the input lines for readability
  16.   LOCATE I%% * 2, 1: PRINT "INPUT VALUE #"; I%%; "  -"; Inputs(I%%);
  17.   'print a "cursor" to show which input user is on, use space$ to clear other lines
  18.   IF I%% = Opt%% THEN PRINT CHR$(176) ELSE PRINT SPACE$(2)
  19.  NEXT I%%
  20.  
  21.  'let us process which line the user is inputing
  22.  SELECT CASE KBD&
  23.   CASE 13 'enter to accept inputs
  24.    ExitFlag%% = TRUE
  25.   CASE 8 'backspace to clear this input
  26.    Inputs(Opt%%) = ""
  27.   CASE Key_Up
  28.    Opt%% = Opt%% - 1
  29.    'for this example we will stop on 1, we could always cycle to 10 though
  30.    IF Opt%% = 0 THEN Opt%% = 1
  31.   CASE Key_Down
  32.    Opt%% = Opt%% + 1
  33.    'we will cap off at 10, though we could cycle back to 1
  34.    IF Opt%% = 11 THEN Opt%% = 10
  35.   CASE 32 TO 122
  36.    'now we are only going to allow 1 character inputs for this example
  37.    Inputs(Opt%%) = CHR$(KBD&)
  38.   CASE NOT 0 ' any other input(0 is no input)
  39.    BEEP 'invalid input
  40.  '-----------------------------------------------
  41.  
  42.  _LIMIT 30 'up date 30times a sec to save CPU use
  43.  IF KBD& = 27 THEN ExitFlag%% = TRUE 'exit this example
  44. LOOP UNTIL ExitFlag%%
Title: Re: How to leave an input line.
Post by: NOVARSEG on June 12, 2021, 02:36:14 am
@Cobalt
I like the way you combined  a FOR NEXT  inside a DO LOOP

Here are a few mods.  Can enter text . Backspace works

up / down keys rotate now.

Code: QB64: [Select]
  1. 'Editable input example
  2. 'lets start with some base constants
  3. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  4. CONST TRUE = -1, FALSE = NOT TRUE
  5.  
  6. DIM Inputs(9) AS STRING 'for this example we will allow up to 10 inputs
  7.  
  8.  
  9. 'some prep work
  10. OPT = 0 'start on the first input line
  11.  
  12. 'start our loop up
  13.     KH = _KEYHIT 'keyboard input
  14.     IF KH < 0 THEN KH = 0 'negate any negative keyhit values
  15.  
  16.     FOR I = 0 TO 9 'loop through all our input options
  17.  
  18.         'double space the input lines for readability
  19.         LOCATE 1 + (I * 2), 1: PRINT "INPUT VALUE #"; I; "  -"; Inputs(I);
  20.  
  21.         'print a "cursor" to show which input user is on, use space$ to clear other lines
  22.         IF I = OPT THEN PRINT CHR$(176) + " " ELSE PRINT SPACE$(2)
  23.  
  24.     NEXT I
  25.  
  26.     'let us process which line the user is inputing
  27.     SELECT CASE KH
  28.         CASE 13 'enter to accept inputs
  29.             ExitFlag%% = TRUE
  30.         CASE 8 'backspace to clear this input
  31.  
  32.             Inputs(OPT) = LEFT$(Inputs(OPT), LEN(Inputs(OPT)) - 1)
  33.  
  34.         CASE Key_Up
  35.             IF OPT = 0 THEN OPT = 10
  36.             IF OPT > 0 THEN OPT = OPT - 1
  37.  
  38.         CASE Key_Down
  39.  
  40.             IF OPT < 10 THEN OPT = OPT + 1
  41.             IF OPT = 10 THEN OPT = 0
  42.  
  43.         CASE 32 TO 122
  44.             'now we are only going to allow 1 character inputs for this example
  45.             Inputs(OPT) = Inputs(OPT) + CHR$(KH)
  46.         CASE NOT 0 ' any other input(0 is no input)
  47.             BEEP 'invalid input
  48.     END SELECT
  49.     '-----------------------------------------------
  50.  
  51.     _LIMIT 30 'up date 30times a sec to save CPU use
  52.     IF KH = 27 THEN ExitFlag%% = TRUE 'exit this example
  53. LOOP UNTIL ExitFlag%%
  54.  

Added blinking cursor


Code: QB64: [Select]
  1. 'Editable input example
  2. 'lets start with some base constants
  3. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  4. CONST TRUE = -1, FALSE = NOT TRUE
  5.  
  6. DIM Inputs(9) AS STRING 'for this example we will allow up to 10 inputs
  7. DIM cp(30)
  8.  
  9.  
  10. 'some prep work
  11. OPT = 0 'start on the first input line
  12.  
  13. 'start our loop up
  14.     KH = _KEYHIT 'keyboard input
  15.     IF KH < 0 THEN KH = 0 'negate any negative keyhit values
  16.  
  17.     FOR I = 0 TO 9 'loop through all our input options
  18.  
  19.         'double space the input lines for readability
  20.         LOCATE 1 + (I * 2), 1: PRINT "INPUT VALUE #"; I; Inputs(I)
  21.  
  22.         IF I = OPT THEN
  23.             LOCATE 1 + (OPT * 2), cp(OPT) + 17: PRINT " "
  24.         END IF
  25.  
  26.     NEXT I
  27.     LOCATE 1 + (OPT * 2), cp(OPT) + 17, 1, 31, 31
  28.  
  29.  
  30.     'let us process which line the user is inputing
  31.     SELECT CASE KH
  32.  
  33.         CASE 13 'enter to accept inputs
  34.             ExitFlag%% = TRUE
  35.  
  36.         CASE 8 'backspace to clear this input
  37.             IF cp(OPT) > 0 THEN
  38.                 Inputs(OPT) = LEFT$(Inputs(OPT), LEN(Inputs(OPT)) - 1)
  39.                 cp(OPT) = cp(OPT) - 1
  40.             END IF
  41.  
  42.         CASE Key_Up
  43.             IF OPT = 0 THEN OPT = 10
  44.             IF OPT > 0 THEN OPT = OPT - 1
  45.  
  46.         CASE Key_Down
  47.  
  48.             IF OPT < 10 THEN OPT = OPT + 1
  49.             IF OPT = 10 THEN OPT = 0
  50.  
  51.         CASE 32 TO 122
  52.             'now we are only going to allow 1 character inputs for this example
  53.             Inputs(OPT) = Inputs(OPT) + CHR$(KH)
  54.             cp(OPT) = cp(OPT) + 1
  55.         CASE NOT 0 ' any other input(0 is no input)
  56.             BEEP 'invalid input
  57.     END SELECT
  58.     '-----------------------------------------------
  59.  
  60.     _LIMIT 30 'up date 30times a sec to save CPU use
  61.     IF KH = 27 THEN ExitFlag%% = TRUE 'exit this example
  62. LOOP UNTIL ExitFlag%%
  63.  
Title: Re: How to leave an input line.
Post by: bartok on June 15, 2021, 02:39:05 am
Cobalt and NOVARSEG,
thank you very much to both! It almost seems what I am searching. The idea to create a custom input routine is sharp. I have to study it in ordet to apply it to the program. Why I has a bouble %%? I know as variable definition $, %, &, !, but %%?
Title: Re: How to leave an input line.
Post by: Richard on June 15, 2021, 05:31:06 am
@bartok

From the QB64  IDE Help > Alphabetical  (a few "pages" back from the very end)




    Variable Name Type Suffixes
þ $ STRING text character type: 1 byte
þ ! SINGLE floating decimal point numerical type (4 bytes)
þ # DOUBLE floating decimal point numerical type (8 bytes)
þ ## _FLOAT QB64 decimal point numerical type (32 bytes)
þ ~ _UNSIGNED QB64 whole positive numerical type when it precedes the 6 numerical
  suffixes below:
þ % INTEGER whole numerical type (2 bytes)
þ & LONG whole numerical type (4 bytes}
þ && _INTEGER64 QB64 whole numerical type (8 bytes)
þ ` _BIT QB64 whole numerical type (1 bit) (Key below tilde (~) or CHR$(96))
þ %% _BYTE QB64 whole numerical type (1 byte)
þ %& _OFFSET QB64 whole numerical pointer address type (any byte size required)

Hope this helps
Title: Re: How to leave an input line.
Post by: bplus on June 15, 2021, 07:45:54 am
Nice @Cobalt and @NOVARSEG

I made some mods for how I would like to use:
Code: QB64: [Select]
  1. Option _Explicit ' to remind what I haven't dim'd
  2. Dim As Long cursor, nInputs, i
  3. Dim k$
  4. 'setups
  5. nInputs = 6 'for this example we will allow up to nInputs inputs
  6. Dim Inputs$(1 To nInputs)
  7. Dim prompts$(1 To nInputs)
  8. prompts$(1) = "First Name: "
  9. prompts$(2) = " Last Name: "
  10. prompts$(3) = "Home Phone: "
  11. prompts$(4) = "Cell Phone: "
  12. prompts$(5) = "Birth date: "
  13. prompts$(6) = "     State: "
  14. cursor = 1 'start on the first input line
  15. 'start our loop up
  16.     k$ = InKey$ 'keyboard input
  17.     For i = 1 To nInputs 'loop through all our input options
  18.         Locate i, 1: Print prompts$(i); Inputs$(i);
  19.         'print a "cursor" to show which input user is on, use space$ to clear other lines
  20.         If i = cursor Then Print "_" + " " Else Print Space$(2)
  21.     Next
  22.     If Len(k$) Then 'let us process which line the user is inputing
  23.         Select Case Asc(Right$(k$, 1))
  24.             Case 13: If cursor = nInputs Then Exit Do Else cursor = cursor + 1 ' no exit unless on last line
  25.             Case 8: Inputs$(cursor) = Left$(Inputs$(cursor), Len(Inputs$(cursor)) - 1) 'backspace to clear this input
  26.             Case 27: Exit Do
  27.             Case 72: If cursor > 1 Then cursor = cursor - 1 ' up
  28.             Case 80: If cursor < nInputs Then cursor = cursor + 1 'down
  29.             Case 32 TO 122: Inputs$(cursor) = Inputs$(cursor) + k$
  30.         End Select
  31.     End If
  32.     _Limit 30 'up date 30 times a sec to save CPU use
  33. 'show results of inputs
  34. For i = 1 To nInputs
  35.     Print i, prompts$(i); "= "; Inputs$(i)
  36.  
  37.  
Title: Re: How to leave an input line.
Post by: Dav on June 15, 2021, 09:01:10 am
Nice little snippet, @bplus.  Saving it for future use.  I added CASE 73, 75, 77, 81: 'don't print these to the SELECT CASE ASC(RIGHT$(k$, 1)) area to not show those keys.

- Dav
Title: Re: How to leave an input line.
Post by: bplus on June 15, 2021, 09:46:09 am
Hi @Dav

Yeah, the working in of the cursor was simple but genius, NOVARSEG or Cobalt?, in the display update loop,

75, 77 left and right arrow? more up and down? or are we really getting into editing :)

73, 81 pgUp and pgDn make sense, you could start thinking of over a screen full of inputs!

Update:
Code: QB64: [Select]
  1. Option _Explicit ' to remind what I haven't dim'd  B+ mod Cobalt and NOVARSEG and Dav 2021-06-15
  2. Dim As Long cursor, nInputs, i
  3. Dim k$
  4. 'setups
  5. nInputs = 6 'for this example we will allow up to nInputs inputs
  6. Dim Inputs$(1 To nInputs)
  7. Dim prompts$(1 To nInputs)
  8. prompts$(1) = "First Name: "
  9. prompts$(2) = " Last Name: "
  10. prompts$(3) = "Home Phone: "
  11. prompts$(4) = "Cell Phone: "
  12. prompts$(5) = "Birth date: "
  13. prompts$(6) = "     State: "
  14. cursor = 1 'start on the first input line
  15. 'start our loop up
  16.     k$ = InKey$ 'keyboard input
  17.     For i = 1 To nInputs 'loop through all our input options
  18.         Locate i, 1: Print prompts$(i); Inputs$(i);
  19.         'print a "cursor" to show which input user is on, use space$ to clear other lines
  20.         If i = cursor Then Print "_" + " " Else Print Space$(2)
  21.     Next
  22.     If Len(k$) Then 'let us process which line the user is inputing
  23.         Select Case Asc(Right$(k$, 1))
  24.             Case 13: If cursor = nInputs Then Exit Do Else cursor = cursor + 1 ' no exit unless on last line
  25.             Case 8: Inputs$(cursor) = Left$(Inputs$(cursor), Len(Inputs$(cursor)) - 1) 'backspace to clear this input
  26.             Case 27: Exit Do
  27.             Case 72, 75: If cursor > 1 Then cursor = cursor - 1 ' up
  28.             Case 73: cursor = 1 'pgUp
  29.             Case 80, 77: If cursor < nInputs Then cursor = cursor + 1 'down
  30.             Case 81: cursor = nInputs ' pgDn
  31.             Case 32 TO 122: Inputs$(cursor) = Inputs$(cursor) + k$
  32.         End Select
  33.     End If
  34.     _Limit 30 'up date 30times a sec to save CPU use
  35. 'show results of inputs
  36. For i = 1 To nInputs
  37.     Print i, prompts$(i); "= "; Inputs$(i)
  38.  
  39.  
Title: Re: How to leave an input line.
Post by: TempodiBasic on June 15, 2021, 05:30:32 pm
Hi
it is so fine to see how different and similar approaches have been showed here for a customized input routine.

@bartok
as our friends have said it is no possible navigation trough the input lines if you use old standard INPUT/ LINE INPUT / INPUT$()  keywords. Please forgot them because you will not want a DOS  interface with black screen.
Title: Re: How to leave an input line.
Post by: bartok on June 16, 2021, 08:48:21 am
@Cobalt
I like the way you combined  a FOR NEXT  inside a DO LOOP

Here are a few mods.  Can enter text . Backspace works

up / down keys rotate now.

Code: QB64: [Select]
  1. 'Editable input example
  2. 'lets start with some base constants
  3. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  4. CONST TRUE = -1, FALSE = NOT TRUE
  5.  
  6. DIM Inputs(9) AS STRING 'for this example we will allow up to 10 inputs
  7.  
  8.  
  9. 'some prep work
  10. OPT = 0 'start on the first input line
  11.  
  12. 'start our loop up
  13.     KH = _KEYHIT 'keyboard input
  14.     IF KH < 0 THEN KH = 0 'negate any negative keyhit values
  15.  
  16.     FOR I = 0 TO 9 'loop through all our input options
  17.  
  18.         'double space the input lines for readability
  19.         LOCATE 1 + (I * 2), 1: PRINT "INPUT VALUE #"; I; "  -"; Inputs(I);
  20.  
  21.         'print a "cursor" to show which input user is on, use space$ to clear other lines
  22.         IF I = OPT THEN PRINT CHR$(176) + " " ELSE PRINT SPACE$(2)
  23.  
  24.     NEXT I
  25.  
  26.     'let us process which line the user is inputing
  27.     SELECT CASE KH
  28.         CASE 13 'enter to accept inputs
  29.             ExitFlag%% = TRUE
  30.         CASE 8 'backspace to clear this input
  31.  
  32.             Inputs(OPT) = LEFT$(Inputs(OPT), LEN(Inputs(OPT)) - 1)
  33.  
  34.         CASE Key_Up
  35.             IF OPT = 0 THEN OPT = 10
  36.             IF OPT > 0 THEN OPT = OPT - 1
  37.  
  38.         CASE Key_Down
  39.  
  40.             IF OPT < 10 THEN OPT = OPT + 1
  41.             IF OPT = 10 THEN OPT = 0
  42.  
  43.         CASE 32 TO 122
  44.             'now we are only going to allow 1 character inputs for this example
  45.             Inputs(OPT) = Inputs(OPT) + CHR$(KH)
  46.         CASE NOT 0 ' any other input(0 is no input)
  47.             BEEP 'invalid input
  48.     END SELECT
  49.     '-----------------------------------------------
  50.  
  51.     _LIMIT 30 'up date 30times a sec to save CPU use
  52.     IF KH = 27 THEN ExitFlag%% = TRUE 'exit this example
  53. LOOP UNTIL ExitFlag%%
  54.  

Added blinking cursor


Code: QB64: [Select]
  1. 'Editable input example
  2. 'lets start with some base constants
  3. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  4. CONST TRUE = -1, FALSE = NOT TRUE
  5.  
  6. DIM Inputs(9) AS STRING 'for this example we will allow up to 10 inputs
  7. DIM cp(30)
  8.  
  9.  
  10. 'some prep work
  11. OPT = 0 'start on the first input line
  12.  
  13. 'start our loop up
  14.     KH = _KEYHIT 'keyboard input
  15.     IF KH < 0 THEN KH = 0 'negate any negative keyhit values
  16.  
  17.     FOR I = 0 TO 9 'loop through all our input options
  18.  
  19.         'double space the input lines for readability
  20.         LOCATE 1 + (I * 2), 1: PRINT "INPUT VALUE #"; I; Inputs(I)
  21.  
  22.         IF I = OPT THEN
  23.             LOCATE 1 + (OPT * 2), cp(OPT) + 17: PRINT " "
  24.         END IF
  25.  
  26.     NEXT I
  27.     LOCATE 1 + (OPT * 2), cp(OPT) + 17, 1, 31, 31
  28.  
  29.  
  30.     'let us process which line the user is inputing
  31.     SELECT CASE KH
  32.  
  33.         CASE 13 'enter to accept inputs
  34.             ExitFlag%% = TRUE
  35.  
  36.         CASE 8 'backspace to clear this input
  37.             IF cp(OPT) > 0 THEN
  38.                 Inputs(OPT) = LEFT$(Inputs(OPT), LEN(Inputs(OPT)) - 1)
  39.                 cp(OPT) = cp(OPT) - 1
  40.             END IF
  41.  
  42.         CASE Key_Up
  43.             IF OPT = 0 THEN OPT = 10
  44.             IF OPT > 0 THEN OPT = OPT - 1
  45.  
  46.         CASE Key_Down
  47.  
  48.             IF OPT < 10 THEN OPT = OPT + 1
  49.             IF OPT = 10 THEN OPT = 0
  50.  
  51.         CASE 32 TO 122
  52.             'now we are only going to allow 1 character inputs for this example
  53.             Inputs(OPT) = Inputs(OPT) + CHR$(KH)
  54.             cp(OPT) = cp(OPT) + 1
  55.         CASE NOT 0 ' any other input(0 is no input)
  56.             BEEP 'invalid input
  57.     END SELECT
  58.     '-----------------------------------------------
  59.  
  60.     _LIMIT 30 'up date 30times a sec to save CPU use
  61.     IF KH = 27 THEN ExitFlag%% = TRUE 'exit this example
  62. LOOP UNTIL ExitFlag%%
  63.  

Why, if I add on the top of your code,

test& = _NEWIMAGE(_DESKTOPWIDTH, _DESKTOPHEIGHT, 32)
_DEST test&
SCREEN test&

the cursor is not blincking? A part from that, with _NEWIMAGE graphic screen, LOCATE in your program continues to work fine without changes. So it seems that cursorstart and cursorstop may have problems.
Title: Re: How to leave an input line.
Post by: bplus on June 16, 2021, 11:30:54 am
Quote
So it seems that cursorstart and cursorstop may have problems.

In graphics screens.
Title: Re: How to leave an input line.
Post by: bartok on June 16, 2021, 12:08:45 pm
In graphics screens.

yes, but adding \16 and \8 nothing changes. In my program, SCREEN test& (that is called SCREEN schermo&), is the screen where all the images are put, after they have been collected between them.
For example, the attached image of the first post, is the result of an image put 2 times (the 2 graphs) inside a larger image (with datas) finally put in turn on schermo&. I use schermo& to ask inputs to the user or to write some information, but it has to contain also images.

So, is there a way in order to have blinking cursor on test&(schermo&)?

I thounght that implementing navigability was easier and that the worst was over!

However, thanks you all, I have understood the examples and I have done what I wanted. A part from blinking cursor...

Hi
it is so fine to see how different and similar approaches have been showed here for a customized input routine.

@bartok
as our friends have said it is no possible navigation trough the input lines if you use old standard INPUT/ LINE INPUT / INPUT$()  keywords. Please forgot them because you will not want a DOS  interface with black screen.

apart from the fact that I adore DOS inferface with black screen...:D
apart from the fact that, even having implemented this new standar of input, my interface still seems a DOS interface with back screen...

but: implementing this flexible kind of input, is absolutely not a joke, above all if the real case requires well defined kind of inputs! So, if it is not necessary such a flexibility, I think "normal" INPUT is preferable.
Title: Re: How to leave an input line.
Post by: bplus on June 16, 2021, 12:26:49 pm
Well, when you have a graphics screen you can replace a blinking cursor with a B&W blinking BF box option for Line.
If cursor box is not in a cls screen loop that updates in fractions of seconds then use a timer to blink the box.
Title: Re: How to leave an input line.
Post by: SMcNeill on June 16, 2021, 10:01:37 pm
This concept isn't that complex.  Let me strip it down to the very basics for you guys:

Code: QB64: [Select]
  1. Dim result(1 To 3) As String
  2.  
  3. V = 1: T! = Timer
  4.     If V < 1 Then V = 3 Else If V > 3 Then V = 1 'stay in bounds of our array
  5.     If Timer > T! + 0.5 Then blink = Not blink: T! = Timer 'blink on and off timer
  6.     Cls
  7.     Print "Enter your name: "; result(1);: If V = 1 And blink Then Print "Û" Else Print
  8.     Print "Enter your age : "; result(2);: If V = 2 And blink Then Print "Û" Else Print
  9.     Print "Enter your sex : "; result(3);: If V = 3 And blink Then Print "Û" Else Print
  10.     Print "Esc to Accept Data and exit"
  11.     k = _KeyHit
  12.     Select Case k
  13.         Case 18432: V = V - 1 'up
  14.         Case 20480: V = V + 1 'down
  15.         Case 13: V = V + 1 'enter
  16.         Case 8: result(V) = Left$(result(V), Len(result(V)) - 1) 'backspace
  17.         Case 32 TO 255: result(V) = result(V) + Chr$(k) 'add character
  18.     End Select
  19.     _Limit 30
  20.     _Display
  21. Loop Until k = 27
  22. Print: Print "Your final data was:", result(1), result(2), result(3)
  23.  
Title: Re: How to leave an input line.
Post by: bartok on June 17, 2021, 08:47:47 am
This concept isn't that complex.  Let me strip it down to the very basics for you guys:

Code: QB64: [Select]
  1. Dim result(1 To 3) As String
  2.  
  3. V = 1: T! = Timer
  4.     If V < 1 Then V = 3 Else If V > 3 Then V = 1 'stay in bounds of our array
  5.     If Timer > T! + 0.5 Then blink = Not blink: T! = Timer 'blink on and off timer
  6.     Cls
  7.     Print "Enter your name: "; result(1);: If V = 1 And blink Then Print "Û" Else Print
  8.     Print "Enter your age : "; result(2);: If V = 2 And blink Then Print "Û" Else Print
  9.     Print "Enter your sex : "; result(3);: If V = 3 And blink Then Print "Û" Else Print
  10.     Print "Esc to Accept Data and exit"
  11.     k = _KeyHit
  12.     Select Case k
  13.         Case 18432: V = V - 1 'up
  14.         Case 20480: V = V + 1 'down
  15.         Case 13: V = V + 1 'enter
  16.         Case 8: result(V) = Left$(result(V), Len(result(V)) - 1) 'backspace
  17.         Case 32 TO 255: result(V) = result(V) + Chr$(k) 'add character
  18.     End Select
  19.     _Limit 30
  20.     _Display
  21. Loop Until k = 27
  22. Print: Print "Your final data was:", result(1), result(2), result(3)
  23.  

done! thank's!

Code: QB64: [Select]
  1. '[...]
  2. esci$ = "I dati forniti non determinao pioggia efficace, quindi non vi Š portata. Premere un tasto per uscire."
  3. SCREEN schermo&
  4. PRINT "Questo programma serve a calcolare l'idrogramma di progetto (e relativa portata di picco) per"
  5. PRINT "un  dato  tempo  di  ritorno,  utilizzando  l'idrogramma  unitario  adimensionale di Mockus e"
  6. PRINT "ietrogrammi tipo "; CHR$(34); "Chicago"; CHR$(34); " o "; CHR$(34); "costanti"; CHR$(34); "."
  7. PRINT "Di seguito si dovranno inserire i valori della curva di possibilit… climatica "; CHR$(34); "h = Ktúaúd^n"; CHR$(34); "."
  8. PRINT "Se  si dispone  dei valori  del Centro  Funzionale, digitare il valore "; CHR$(34); "Kt"; CHR$(34); " relativo al tempo"
  9. PRINT "di ritorno "; CHR$(34); "T"; CHR$(34); " d'interesse, con i relativi valori "; CHR$(34); "a"; CHR$(34); " e "; CHR$(34); "n"; CHR$(34); "."
  10. PRINT "Se invece si ha una  propria curva di possibilit… climatica, quando verr… chiesto di inserire"
  11. PRINT CHR$(34); "Kt"; CHR$(34); ", digitare "; CHR$(34); "INVIO"; CHR$(34); ", o "; CHR$(34); "1"; CHR$(34); "."
  12. PRINT "In tal caso "; CHR$(34); "Kt"; CHR$(34); " sar… considerato pari a "; CHR$(34); "1"; CHR$(34); " e "; CHR$(34); "T"; CHR$(34); " come "; CHR$(34); "definito dall'utente"; CHR$(34); "."
  13. PRINT "- Kt [-] (INVIO per 1)                                           = "
  14. PRINT "- a [mm/d^n]                                                     = "
  15. PRINT "- n [-] (0ö1)                                                    = "
  16. PRINT "- Area del bacino idrografico [mý]                               = "
  17. PRINT "- Lunghezza dell'asta principale del bacino idrografico [m]      = "
  18. PRINT "- Altitudine s.l.m. del punto pi— alto dell'asta principale [m]  = "
  19. PRINT "- Altitudine s.l.m. del punto pi— basso dell'asta principale [m] = "
  20. PRINT "- Pendenza media del bacino idrografico [%] (1ö100)              = "
  21. PRINT "- CN(II) [-] (1ö100)                                             = "
  22. PRINT "- Coefficiente delle perdite inziali [-] (0ö0.2 - INVIO per 0.1) = "
  23. CALL InserimentoDati(k!, a1!, n1, A2!, L!, HmaxL!, HminL!, s1!, CNII!, CoeffPerditeIniziali!)
  24. LOCATE PosizioneCursore% + 10, 1
  25. PRINT "- Visualizzare i risultati utilizzando lo ietogramma Chicago [1] o costante [2]?"
  26. '[...]
  27. SUB InserimentoDati (k!, a1!, n1, A2!, L!, HmaxL!, HminL!, s1!, CNII!, CoeffPerditeIniziali!)
  28.  
  29.     SHARED PosizioneCursore%
  30.  
  31.     DIM inputs$(10)
  32.     DIM richiesta%
  33.     DIM test%(10)
  34.     DIM debug%
  35.     DIM carattere$
  36.     DIM punti%
  37.     DIM T!
  38.     DIM cursore%
  39.     DIM esci%
  40.  
  41.     PosizioneCursore% = CSRLIN - 10
  42.     richiesta% = 1
  43.     T! = TIMER
  44.     DO
  45.         _LIMIT 30
  46.         KeyPress$ = INKEY$
  47.         IF TIMER > T! + 0.5 THEN
  48.             cursore% = NOT cursore%
  49.             T! = TIMER
  50.         END IF
  51.         FOR i% = 1 TO 10
  52.             LOCATE PosizioneCursore% - 1 + i%, 68: PRINT inputs$(i%) + SPACE$(30)
  53.         NEXT i%
  54.         IF esci% = 1 THEN EXIT DO
  55.         LOCATE PosizioneCursore% - 1 + richiesta%, 68 + LEN(inputs$(richiesta%))
  56.         IF cursore% THEN PRINT "_"
  57.         SELECT CASE KeyPress$
  58.             CASE CHR$(44), CHR$(46) ',e.
  59.                 punti% = 0
  60.                 IF KeyPress$ = CHR$(44) THEN KeyPress$ = CHR$(46)
  61.                 FOR n% = 1 TO LEN(inputs$(richiesta%))
  62.                     carattere$ = MID$(inputs$(richiesta%), n%, 1)
  63.                     IF carattere$ = CHR$(46) THEN punti% = 1
  64.                 NEXT n%
  65.                 SELECT CASE punti%
  66.                     CASE IS = 0
  67.                         inputs$(richiesta%) = inputs$(richiesta%) + KeyPress$
  68.                     CASE IS = 1
  69.                         inputs$(richiesta%) = inputs$(richiesta%)
  70.                 END SELECT
  71.             CASE CHR$(48) TO CHR$(57) '0-9
  72.                 inputs$(richiesta%) = inputs$(richiesta%) + KeyPress$
  73.             CASE CHR$(8) 'del
  74.                 SELECT CASE LEN(inputs$(richiesta%))
  75.                     CASE IS = 0
  76.                         EXIT SELECT
  77.                     CASE IS = 1
  78.                         inputs$(richiesta%) = ""
  79.                         LOCATE , 68: PRINT " "
  80.                     CASE ELSE
  81.                         inputs$(richiesta%) = LEFT$(inputs$(richiesta%), LEN(inputs$(richiesta%)) - 1)
  82.                         LOCATE , 68 + LEN(inputs$(richiesta%)): PRINT " "
  83.                 END SELECT
  84.             CASE CHR$(0) + "H" 'su
  85.                 GOSUB Valutavalore
  86.                 SELECT CASE test%(richiesta%)
  87.                     CASE IS = 0
  88.                         inputs$(richiesta%) = ""
  89.                     CASE IS = 1
  90.                         IF richiesta% = 1 THEN
  91.                             EXIT SELECT
  92.                         ELSEIF richiesta <= 10 THEN
  93.                             richiesta% = richiesta% - 1
  94.                         END IF
  95.                 END SELECT
  96.             CASE CHR$(0) + "P" 'giu'
  97.                 GOSUB Valutavalore
  98.                 SELECT CASE test%(richiesta%)
  99.                     CASE IS = 0
  100.                         inputs$(richiesta%) = ""
  101.                     CASE IS = 1
  102.                         IF richiesta% < 10 THEN
  103.                             IF inputs$(richiesta% + 1) <> "" THEN richiesta% = richiesta% + 1
  104.                         ELSE
  105.                             EXIT SELECT
  106.                         END IF
  107.                 END SELECT
  108.             CASE CHR$(13) 'invio
  109.                 GOSUB Valutavalore
  110.                 IF debug% = 1 THEN
  111.                     _AUTODISPLAY
  112.                     EXIT SUB
  113.                 END IF
  114.                 IF richiesta% <> 1 THEN
  115.                     IF LEN(inputs$(richiesta%)) = 0 THEN test%(richiesta%) = 0
  116.                 END IF
  117.                 SELECT CASE test%(richiesta%)
  118.                     CASE IS = 0
  119.                         richiesta% = richiesta%
  120.                         inputs$(richiesta%) = ""
  121.                     CASE IS = 1
  122.                         IF richiesta% = 10 THEN
  123.                             esci% = 1
  124.                         ELSE
  125.                             richiesta% = richiesta% + 1
  126.                         END IF
  127.                 END SELECT
  128.         END SELECT
  129.         _DISPLAY
  130.     LOOP
  131.     k! = VAL(inputs$(1))
  132.     a1! = VAL(inputs$(2))
  133.     n1! = VAL(inputs$(3))
  134.     A2! = VAL(inputs$(4))
  135.     L! = VAL(inputs$(5))
  136.     HmaxL! = VAL(inputs$(6))
  137.     HminL! = VAL(inputs$(7))
  138.     s1! = VAL(inputs$(8))
  139.     CNII! = VAL(inputs$(9))
  140.     CoeffPerditeIniziali! = VAL(inputs$(10))
  141.     IF k! = 1 THEN
  142.         T$ = "Definito dall'utente."
  143.     ELSE
  144.         GOSUB TrovaT
  145.     END IF
  146.     EXIT SUB
  147.     '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  148.     Valutavalore:
  149.     test%(richiesta%) = 0 ' se 0 rimane nella richiesta in corso, se 1, cambia.
  150.  
  151.     SELECT CASE richiesta%
  152.         CASE 1
  153.             IF inputs$(1) = "123" THEN 'avvia debug
  154.                 'Cillian:
  155.                 'k! = 1: a1! = 1: n1! = 0.45596: A2! = 2641902: L! = 3300: HmaxL! = 1981: HminL! = 1062: s1! = 41.5: CNII! = 70:CoeffPerditeIniziali!=0.1
  156.                 k! = 2.34: a1! = 14.6653: n1! = 0.45596: A2! = 2641902: L! = 3300: HmaxL! = 1981: HminL! = 1062: s1! = 41.5: CNII! = 70: CoeffPerditeIniziali! = 0.1
  157.                 'pialong:
  158.                 'k! = 2.34:'a1! = 17.097811:'n1! = 0.497753:'A2! = 2509318:'L! = 2919:'HmaxL! = 1654:'HminL! = 388:'s1! = 0.663:'CNII! = 66:CoeffPerditeIniziali!=0.1
  159.                 GOSUB TrovaT
  160.                 debug% = 1
  161.                 RETURN
  162.             END IF
  163.             IF LEN(inputs$(richiesta%)) = 0 THEN
  164.                 IF KeyPress$ = CHR$(13) THEN inputs$(richiesta%) = "1"
  165.             END IF
  166.             test%(richiesta%) = 1
  167.         CASE 2, 4, 5, 6, 7
  168.             test%(richiesta%) = 1
  169.         CASE 3
  170.             IF VAL(inputs$(richiesta%)) <= 1 THEN
  171.                 test%(richiesta%) = 1
  172.             ELSE
  173.                 test%(richiesta%) = 0
  174.             END IF
  175.         CASE 8, 9
  176.             IF VAL(inputs$(richiesta%)) >= 1 THEN
  177.                 IF VAL(inputs$(richiesta%)) <= 100 THEN test%(richiesta%) = 1
  178.             ELSEIF inputs$(richiesta%) = "" THEN test%(richiesta%) = 1
  179.             ELSE
  180.                 test%(richiesta%) = 0
  181.             END IF
  182.         CASE IS = 10
  183.             IF LEN(inputs$(richiesta%)) = 0 THEN
  184.                 IF KeyPress$ = CHR$(13) THEN inputs$(richiesta%) = "0.1"
  185.                 test%(richiesta%) = 1
  186.             ELSE
  187.                 IF VAL(inputs$(richiesta%)) >= 0 THEN
  188.                     IF VAL(inputs$(richiesta%)) <= 0.2 THEN test%(richiesta%) = 1
  189.                 ELSE
  190.                     test%(richiesta%) = 0
  191.                 END IF
  192.             END IF
  193.     END SELECT
  194.     '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  195.     TrovaT:
  196.     i% = 1
  197.     '[...]
  198.     RETURN
  199. '-----------------------------------------------------------------------------------------------------------------------------------------------------------
  200.  

I have implemented also the blinking cursor. But all of that is a very complecated stuff, in oder to do things likes these:
- transforms "," in "."
- not allow double "."
- not go DOWN if down the field is empty
- automatic cancel not allowed data
- etc

to do that, more then 200 lines of code!
Title: Re: How to leave an input line.
Post by: SMcNeill on June 17, 2021, 04:33:12 pm
Here's a little something which I tossed together in about 20 minutes this afternoon, which you might be able to use:

Code: QB64: [Select]
  1. Screen _NewImage(1280, 720, 32)
  2. Dim As String prompt(3), results(3)
  3. prompt(0) = "Name": prompt(1) = "Age": prompt(2) = "Sex": prompt(3) = "Phone Number"
  4. For i = 1 To 100 'Draw some stuff on the screen for a background
  5.     Line (Rnd * 1280, Rnd * 720)-(Rnd * 1280, Rnd * 720), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
  6. Print "SLEEPING SO YOU CAN SEE OUR BACKGROUND"
  7. MultiInput 100, 100, prompt(), results(), 20
  8. Print: Print "As you can see, when finished, our pop up restored our background..."
  9. Print "And your answers were the following:"
  10. For i = 0 To UBound(results): Print results(i): Next
  11. Sub MultiInput (xPos, yPos, prompt() As String, results() As String, maxLength As Integer)
  12.     backupImage = _CopyImage(0) 'copy our screen
  13.     B = _Blend: _DontBlend: A = _AutoDisplay: u = UBound(prompt)
  14.     For i = 0 To u 'get box size
  15.         p = _PrintWidth(prompt(i)): If p > maxWidth Then maxWidth = p
  16.     Next
  17.     boxWidth = maxWidth + maxLength * _FontWidth + 10: boxheight = (u + 1) * (_FontHeight + 3)
  18.     Do
  19.         If Timer > t# + .5 Then blink = Not blink: t# = Timer
  20.         k = _KeyHit 'get input
  21.         Select Case k
  22.             Case 18432: selection = selection - 1: If selection < 0 Then selection = u 'up
  23.             Case 20480, 13: selection = selection + 1: If selection > u Then selection = 0 'down
  24.             Case 27: Exit Do 'esc is the exit/finish code
  25.             Case 8: results(selection) = Left$(results(selection), Len(results(selection)) - 1) 'backspace
  26.             Case 32 TO 255: results(selection) = results(selection) + Chr$(k) 'all else
  27.         End Select
  28.  
  29.         _PutImage , backupImage 'restore background
  30.         Line (xPos, yPos)-Step(boxWidth, boxheight), 0, BF: Line (x + xPos + maxWidth + 1, y + yPos)-Step(0, boxheight), -1 'draw box
  31.         For i = 0 To u
  32.             Line (x + xPos, y + i * (_FontHeight + 3) + yPos)-Step(boxWidth, _FontHeight + 3), -1, B
  33.             _PrintString (x + xPos + 2, y + i * (_FontHeight + 3) + yPos + 2), prompt(i)
  34.             If i = selection And blink Then out$ = results(i) + Chr$(219) Else out$ = results(i)
  35.             _PrintString (x + xPos + maxWidth + 3, y + i * (_FontHeight + 3) + yPos + 2), out$
  36.         Next
  37.         _Limit 30: _Display
  38.     Loop
  39.     _PutImage , backupImage
  40.     If B Then _Blend
  41.     _FreeImage backupImage

45 lines total, and  only 33 lines for our SUB, which does all the real work for us.

And what's this do, you ask?

It creates a simple, stand-alone, multi-line, POP-UP input box which we can use the arrow keys to move up and down between. 

Usage is rather simple:
1) Dim 2 arrays to hold your prompts and the results.
2) Set your prompts.
3) Call the function, get the results.

Can't be much simpler than that!