Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-Input Popup Box
#1
(I'd posted this elsewhere, but thought I'd share it here so folks who might not be reading the other topic could locate this and maybe someday reference it, or make use of it, for their own stuff.)

Here's a little something which I tossed together in about 20 minutes this afternoon, which you might be able to use:


Code: (Select All)
Screen _NewImage(1280, 720, 32)
Dim As String prompt(3), results(3)
prompt(0) = "Name": prompt(1) = "Age": prompt(2) = "Sex": prompt(3) = "Phone Number"
For i = 1 To 100 'Draw some stuff on the screen for a background
    Line (Rnd * 1280, Rnd * 720)-(Rnd * 1280, Rnd * 720), _RGB32(Rnd * 255, Rnd * 255, Rnd * 255), BF
Next
Print "SLEEPING SO YOU CAN SEE OUR BACKGROUND"
Sleep
MultiInput 100, 100, prompt(), results(), 20
Print: Print "As you can see, when finished, our pop up restored our background..."
Print "And your answers were the following:"
For i = 0 To UBound(results): Print results(i): Next
Sub MultiInput (xPos, yPos, prompt() As String, results() As String, maxLength As Integer)
    backupImage = _CopyImage(0) 'copy our screen
    B = _Blend: _DontBlend: A = _AutoDisplay: u = UBound(prompt)
    For i = 0 To u 'get box size
        p = _PrintWidth(prompt(i)): If p > maxWidth Then maxWidth = p
    Next
    boxWidth = maxWidth + maxLength * _FontWidth + 10: boxheight = (u + 1) * (_FontHeight + 3)
    Do
        If Timer > t# + .5 Then blink = Not blink: t# = Timer
        k = _KeyHit 'get input
        Select Case k
            Case 18432: selection = selection - 1: If selection < 0 Then selection = u 'up
            Case 20480, 13: selection = selection + 1: If selection > u Then selection = 0 'down
            Case 27: Exit Do 'esc is the exit/finish code
            Case 8: results(selection) = Left$(results(selection), Len(results(selection)) - 1) 'backspace
            Case 32 TO 255: results(selection) = results(selection) + Chr$(k) 'all else
        End Select

        _PutImage , backupImage 'restore background
        Line (xPos, yPos)-Step(boxWidth, boxheight), 0, BF: Line (x + xPos + maxWidth + 1, y + yPos)-Step(0, boxheight), -1 'draw box
        For i = 0 To u
            Line (x + xPos, y + i * (_FontHeight + 3) + yPos)-Step(boxWidth, _FontHeight + 3), -1, B
            _PrintString (x + xPos + 2, y + i * (_FontHeight + 3) + yPos + 2), prompt(i)
            If i = selection And blink Then out$ = results(i) + Chr$(219) Else out$ = results(i)
            _PrintString (x + xPos + maxWidth + 3, y + i * (_FontHeight + 3) + yPos + 2), out$
        Next
        _Limit 30: _Display
    Loop
    _PutImage , backupImage
    If B Then _Blend
    If A Then _AutoDisplay
    _FreeImage backupImage
End Sub

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!
Reply


Messages In This Thread
Multi-Input Popup Box - by SMcNeill - 04-23-2022, 05:12 PM



Users browsing this thread: 1 Guest(s)