Console Multi_prompt Input
#1
Use the Console for multi-prompt inputs.
The routine is shown here with a simple example.
Code: (Select All)
'Console multi_input
'
'an example program for a routine to use the console window for multi-line input prompts
$Console
_Console Off 'turn off the console for now
_Delay 0.1
Print "Press any key when ready."
Sleep
Cls
Dim p$(5), aa$(5)
'setup the input prompts
p$(1) = "First Name : "
p$(2) = "Middle     : "
p$(3) = "Last Name  : "
p$(4) = "Street     : "
p$(5) = "City/Town  : "
multi_input "Multi_Input Sample", p$(), aa$()
Print aa$(3); ", "; aa$(1); " "; aa$(2)
Print aa$(4); ", "; aa$(5)
End

Sub multi_input (cptitle$, prompt$(), ia$())
    'cptitle$ is the console prompt title
    'prompt$() array of prompts
    'ia$() array of input data
    ind& = _Dest 'get the screen
    _Console On 'turn the console back on
    If cptitle$ = "" Then _ConsoleTitle "Prompt" Else _ConsoleTitle cptitle$ 'set the console title
    _ScreenHide 'hide the mainscreen
    _Dest _Console
    Cls 'clear the console
    mi = UBound(prompt$) 'check how many entries are being asked for
    For n = 1 To mi 'print the prompts
        Print prompt$(n)
    Next n
    Locate 1, 1 'reset cursor to top left corner
    For n = 1 To mi 'reprint prompts and get the input
        Print prompt$(n);
        Input ia$(n)
    Next n
    _ScreenShow
    _Dest ind&
    _Console Off
End Sub
Reply
#2
In a QB64 version earlier than v3.5 this method of getting input from the user would work well. Otherwise users would expect a pretty window to do that. Could almost call upon "yad" or "zenity" on Linux but either one has to be installed, if not then it has to be done in the way prescribed in this thread.

Doesn't Windows have a way to display a dialog to receive input, at least like an "Input Box", or does it still have to be done with the API?

Another thing is that the user of this presented program has to cooperate. What if he/she made a mistake and needs to start over, or he/she entered something in the "wrong" field? INPUT is almost never used these days because of it, and LINE INPUT is almost relegated to text file input. Those two keywords and "scanf()" and "gets()" in C and whatever looked like them became obsolete the moment the few full-screen editors came out such as the QBasic editor.

This is to inform somebody who is getting acquainted with BASIC programming or with QB64, and understands that a program of this type could be for his/her own use only and knows how to do it right.
Reply
#3
(07-07-2023, 01:58 AM)mnrvovrfc Wrote: In a QB64 version earlier than v3.5 this method of getting input from the user would work well. Otherwise users would expect a pretty window to do that. Could almost call upon "yad" or "zenity" on Linux but either one has to be installed, if not then it has to be done in the way prescribed in this thread.

Doesn't Windows have a way to display a dialog to receive input, at least like an "Input Box", or does it still have to be done with the API?

Another thing is that the user of this presented program has to cooperate. What if he/she made a mistake and needs to start over, or he/she entered something in the "wrong" field? INPUT is almost never used these days because of it, and LINE INPUT is almost relegated to text file input. Those two keywords and "scanf()" and "gets()" in C and whatever looked like them became obsolete the moment the few full-screen editors came out such as the QBasic editor.

This is to inform somebody who is getting acquainted with BASIC programming or with QB64, and understands that a program of this type could be for his/her own use only and knows how to do it right.
One can use PowerShell to make a dialog that returns the text input from the user. It can work well, provided the coder knows PowerShell decently enough. But WinAPI is my preferred method. Also, good thing mentioning Zenity. I've used it before in Linux through QB64 for doing all sorts of dialogs. It's a great tool. A little off topic, but I remember someone made a Zenity for Windows on GitHub and it was horrible. It kills all your environment variables and your PATH, totally ruining your PC. I had to use a restore point to fix everything.
Schuwatch!
Yes, it's me. Now shut up.
Reply
#4
I just wanted a simple programming method that was cross platform because it didn't require any  API calls or even shell commands that may have been system specific, and it's also comprehensible to beginners.
Reply
#5
(07-07-2023, 02:17 PM)James D Jarvis Wrote: I just wanted a simple programming method that was cross platform because it didn't require any  API calls or even shell commands that may have been system specific, and it's also comprehensible to beginners.

Here I have shown 4 alternate methods not specifically intended for console.
https://staging.qb64phoenix.com/showthre...8#pid17118

This is pretty simple and should work on console:
Code: (Select All)
_Title "Multiple Input Menu demo" 'b+ 2021-06-11

Type InputItem
    As String promptName, SValue
End Type

ReDim Shared nItems
nItems = 12 ' number of inputs plus 2 for quit and goto for processing inputs

' initial item names (like variables)
ReDim inps(1 To nItems) As InputItem
For i = 1 To nItems - 2
    inps(i).promptName = "Demo Input Item #" + _Trim$(Str$(i))
Next
inps(nItems - 1).promptName = "Process Inputs"
inps(nItems).promptName = "Quit"
Do
    Cls
    For i = 1 To nItems
        Print "#" + _Trim$(Str$(i)), inps(i).promptName;
        If inps(i).SValue <> "" Then Print " = "; inps(i).SValue Else Print
    Next
    Print: Input "Enter choice # "; choice
    If choice < nItems - 1 Then
        Print "Please enter, " + inps(choice).promptName + " ";
        Input inps(choice).SValue
    End If
Loop Until choice >= nItems - 1 And choice <= nItems
Select Case choice
    Case nItems: Print "You quit, goodbye!": End
    Case nItems - 1
        ' <<< could check inputs here and handle errors
        GoTo processInputs
End Select

processInputs:
' doit  remember SValues are strings!
Print "Processing Inputs now..."

This allows user to edit their inputs by menu numbers until they press enter at last input item (enters on others just prompt next input item).
This is like for filling out a form without having to design a form.
b = b + ...
Reply




Users browsing this thread: 2 Guest(s)