Solved

Input Box with Radio Buttons

Posted on 2001-07-31
9
1,319 Views
Last Modified: 2008-03-10
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?????????
0
Comment
Question by:darold_rudolph
9 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 6338887
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...
0
 
LVL 27

Expert Comment

by:Ark
ID: 6338888
Hi
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

Cheers
0
 
LVL 5

Accepted Solution

by:
KDivad earned 200 total points
ID: 6339113
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?
    Next
    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


Use:

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...
0
 
LVL 5

Expert Comment

by:KDivad
ID: 6339117
Sorry:

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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:TigerZhao
ID: 6339467
'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)
    Next
    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

0
 
LVL 5

Expert Comment

by:KDivad
ID: 6339823
Gee, that kinda looks familiar...
0
 

Author Comment

by:darold_rudolph
ID: 6341432
KDivad had the answer first
0
 

Author Comment

by:darold_rudolph
ID: 6341462
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!

0
 
LVL 5

Expert Comment

by:KDivad
ID: 6342781
<< 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!

Later,
KDL
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now