Results 1 to 4 of 4

Thread: easy control array question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    I have a control array of 3 option buttons on my form. I want to hit a command button which pops up a msgbox and let's me know which option index is currently selected.

    Thanks,

    Dan

  2. #2
    Guest
    Try this:

    Code:
    Private Sub Command1_Click()
    For i = 0 To 2
    opt = Option1(i).Value
    If opt = True Then opt = Option1(i).Index: Exit For
    Next i
    MsgBox "Option1(" & opt & ")"
    End Sub

  3. #3
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    hmm

    on the click event of your command button

    suppose option1(0), option1(1), option1(2) are your option buttons

    do something like
    if option1(0).value = true then
    msgbox "0"
    else if option1(1).value = true then
    msgbox "1"
    etc...


    This is the answer in its simplest form
    I am guessing you're new to VB

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Actually, in it's simplist form:

    Since only one option box may be selected at any one time:

    Code:
    Option Explicit
    Dim opt as Integer
    
    Private Sub Option1_Click(Index As Integer)
      ' saves the selected option button index to a module variable
      opt = Index
    End Sub
    
    Private Sub Command1_Click()
       MsgBox opt
    End Sub
    Cheers
    Paul Lewis

Posting Permissions

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



Click Here to Expand Forum to Full Width