Input Box with Radio Buttons

I need an "InputBox" with Radio Buttons instead of the textBox in the VB "InputBox" control

It needs to behave the similar to the VB "Input Box" control.

I need to pass the 4 or 5 captions, set a defaul, pass control to the "Input Box" wait until the User presses OK and retrieve the result back into the main program.  The main program then continues.

The questions for the input box differ at different times.

I have had no luck with vbmodal forms.  Can't pass the captions, before displaying modal form.

I have had no luck with vbModeless forms. Does pass control to the input form and pause the main program.

I have researched this a bit.  I can't find a simple answer, so there must be a trick

Any suggestions?????????
Who is Participating?
KDivadConnect With a Mentor Commented:
My idea:

Create your form as it should be shown (OK, Cancel, 4 options in a control array, etc.), then add this to it:

Private OptSel As Long
Public Function InputOption(ByVal Caption As String, ByVal Prompt As String, ParamArray Opts() As String) As Long

    Me.Caption = Caption
    Label1.Caption = Prompt
    For I = 0 To 3
        Option1(I) = Opts(I) 'ParamArray starts with 0?
    Me.Show 1
    InputOption = OptSel

End Function
Private Sub Option1_Click(Index As Integer)

    OptSel = Index

End Sub
Private Sub cmdOK_Click()

    Unload Me

End Sub
Private Sub cmdCancel_Click()

    OptSel = -1
    Unload Me

End Sub


MsgBox InputOption(App.Title, "Please select an option:", "Option 1", "Option 2", "Option 3", "Option 4")

It will return -1 if canceled, otherwise 0 to 3.

It's the same idea I use for my own custom InputBox...
You're on the right track with the vbModal form.  What you may have missed are the correct event procedures (Form_Load, Command1_Click, etc.) to use.

Whatever code you have in the Form_Load should probably go in Form_Activate; you may want to use some form-level public variables to control the return values, etc. and have the calling form check those to see their status.

Describe a bit about the event procedures you use...
You can use 2 ways:
1. Declare Captions names as Public in Bas module:
Public Cap1 As String, Cap2 As String.....

At Input_Form_Load Event:
Option1.Caption = Cap1
Option2.Caption = Cap2

And before calling this form:
Cap1 = "anycap1"
Cap2 = "anycap2"

2. Use Publi Property Let/Get construction inside Input_Form

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


MsgBox FormName.InputOption(App.Title ...

One other thing: I included code to let you show a prompt on a label. Remove it if you don't need a label for longer instructions.
'Add a form
  Name = frmSingleSelect
  BorderStyle = 3 'Fixed Dialog
  'Add a option button
    Name = opt
    Index = 0
  'Add a command button
    Name = cmdOK
    Caption = &OK
    Default = True
  'Add another command button
    Name = cmdCancel
    Caption = &Cancel
    Cancel = True
'Code like this
Option Explicit

Private Const LNG_GAP = 120

Private m_bReturn   As Boolean
Private m_lIndex    As Long

Public Function Action(ByRef Index As Long, ParamArray Captions()) As Boolean
    Dim lUBound         As Long
    Dim I               As Long
    Load Me
    m_bReturn = False
    m_lIndex = -1
    lUBound = UBound(Captions)
    For I = 0 To lUBound
        If I > 0 Then
            Load opt(I)
            opt(I).Top = opt(I - 1).Top + opt(I - 1).Height + LNG_GAP
            opt(I).Visible = True
        End If
        opt(I).Caption = Captions(I)
    opt(Index).Value = True
    m_lIndex = Index
    Me.Show vbModal
    If m_bReturn Then
        Index = m_lIndex
    End If
    Action = m_bReturn
End Function

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdOK_Click()
    m_bReturn = True
    Unload Me
End Sub

Private Sub opt_Click(Index As Integer)
    m_lIndex = Index
End Sub
'and the calling code
    Dim lIndex          As Long
    lIndex = 0
    If frmSingleSelect.Action(lIndex, "Top", "Right", "Bottom", "Left") Then
        Select Case lIndex
            Case 0: Debug.Print "Top"
            Case 1: Debug.Print "Right"
            Case 2: Debug.Print "Bottom"
            Case 3: Debug.Print "Left"
        End Select
    End If

Gee, that kinda looks familiar...
darold_rudolphAuthor Commented:
KDivad had the answer first
darold_rudolphAuthor Commented:
This was exactly what I as looking for, Thanks.  Your reponse was complete.

Also the Call statement of:

intResponse =  frmForm1.InputOption(App.Title, "Please select an option:", "Option 1", "Option 2", "Option 3", "Option 4")

allows me to use the intResponse value of -1 or 0 to 3 in my calling program.

Thanks again!

I love this! I get answer while I sleep! No Worries!

Thanks everyone for responding!

<< I love this! I get answer while I sleep! No Worries! >>

That's why us insomniacs are here! <grin>

I'm glad I could help you out!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.