Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005

    Unanswered: Reference Index From Control Array

    Can anyone help me?

    I'm fairly new to Visual Basic(6) and my problem is this....

    I have three option buttons set up as a control array on a form. One will always be selected.

    I also have a command button on the form. When I click the command button I want to take a certain action depeding upon the option button selected. I guess that I will have to pass the index value of the option button to the on-click event of the command button but don't know how to do it.

    Any help would be appreciated.

  2. #2
    Join Date
    May 2004
    Probably, the most drawn out way to do it is simple if-then statements. The problem you may be having is that there is no index set to indicate which option is selected. Each Opion button is a separate object and must be treated as such. They just have similar properties.

    Private Sub Command1_Click()
    if option1(0).value = vbTrue then
    do whatever
    elsif option1(1).value = vbTrue then
    do something else
    elsif option1(2).value = vbTrue then
    do the last thing
    else there has been an error

    End Sub

    Or a better way might be a do-loop then a case (because if-thens cause a lot of overhead.)

    Private Sub Command1_Click()
    dim X as integer
    X = 0
    DO WHILE option1(X).value = vbFalse
    X = X + 1

    CASE 0
    do code for Option 0 selected
    CASE 1
    do code for option 1 selected
    CASE 2
    do code for option 2 selected

    End Sub

    And as always, there is still more ways to do it. Some would cause more overhead then another, but in your case I think either way you choose the overhead will be minimal.

  3. #3
    Join Date
    Mar 2005
    That worked a treat. Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts