Array of controls - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Array of controls

G.ManivannanG.Manivannan Posts: 43Member
Hai,

I want to create array of controls for ex radiobuttons and panel controls at runtime. There should be 2 or more radio button on each panel controls.
Then if check any one radio button on all panel controls and finally i have to click the submit button to get the all checked radiobuttons text in the msgbox.

How can i do this?

I am new to programming.

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    Wa? Explain that again?

    You want to create 3 or so sets of the same radio buttons, when you click a radio button on one set, it sets it in all of them? Then if you click submit it tells you if they are all checked or not?

    : Hai,
    :
    : I want to create array of controls for ex radiobuttons and panel
    : controls at runtime. There should be 2 or more radio button on each
    : panel controls.
    : Then if check any one radio button on all panel controls and finally
    : i have to click the submit button to get the all checked
    : radiobuttons text in the msgbox.
    :
    : How can i do this?
    :
    : I am new to programming.
    :
  • G.ManivannanG.Manivannan Posts: 43Member
    Hai
    "[color=Green]You want to create 3 or so sets of the same radio buttons, when you
    click a radio button on one set[/color]." upto this the logic is correct.

    after this, I am going to check only one radiobutton in each and every set.
    Then if click submit, it should give the text of checked radiobutton of all sets separately.


    : Wa? Explain that again?
    :
    : You want to create 3 or so sets of the same radio buttons, when you
    : click a radio button on one set, it sets it in all of them? Then if
    : you click submit it tells you if they are all checked or not?
    :
    : : Hai,
    : :
    : : I want to create array of controls for ex radiobuttons and panel
    : : controls at runtime. There should be 2 or more radio button on each
    : : panel controls.
    : : Then if check any one radio button on all panel controls and finally
    : : i have to click the submit button to get the all checked
    : : radiobuttons text in the msgbox.
    : :
    : : How can i do this?
    : :
    : : I am new to programming.
    : :
    :

    G.Manivannan, M.Sc.,[IT],
    VBA Programmer,
    AKUVA Infotech, Bangalore.
  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    On the submit buttons try this code
    [code]
    Dim Ctl As Control
    Dim rBtn As RadioButton
    For Each Ctl In Me.Controls
    Try
    For Each rBtn In Ctl.Controls
    If rBtn.Checked = True Then
    MsgBox(rBtn.Text & " is checked.", MsgBoxStyle.SystemModal & MsgBoxStyle.OKOnly)
    End If
    Next
    Catch ex As Exception
    'ctl was not a panel
    End Try
    Next
    [/code]

    Basically what this code does is Iterates through each Control on Me (the form) and then "Trys" to iterate through the controls contained by Ctl. If Ctl is not a panel it will through an Error so I put it in a Try Catch to have it skip whenever it hits a non-panel. The nested loop iterates through each Radio button in each panel and does a MsgBox when it's checked.

    Should work for any number of panel and Radio buttons.
  • G.ManivannanG.Manivannan Posts: 43Member
    Hai,
    The code is working fine. Thanks a lot.


    G.Manivannan, M.Sc.,[it],
    VBA Programmer,
    AKUVA Infotech, Bangalore.
Sign In or Register to comment.