• Confused about control arrays (VB5)

    Author
    Topic
    #361600

    Trying to understand how control arrays work in VB5 — I think that I am getting confused by trying to use Access97 syntax.

    I have a control array called Sync1, and it has three Option Buttons with Index values of 0, 1, and 2. What I want to do is to call a function like this:

    x = SomeFunction(sync1)

    and I want it to pass a 0, 1, or 2 depending on which Option Button is selected.

    How do I refer to the current value of the array? I am used to dropping option buttons into a frame in Access, and referring to the value of the frame. Does the same principle apply?? Or am overlooking something very obvious?
    frown

    Thanks for your help

    Viewing 0 reply threads
    Author
    Replies
    • #547141

      Jack, it would be good if you changed the name of your control array to optSync1. Just nitpicky of me, but that way other VB programmers will know that they are option buttons (I usually also add an s at the end so that I know that it is more than one button). You can only refer to the value of each one of the buttons in this array: optSync1(0).Value, optSync1(1).Value, and optSync1(2).Value. Each of these values is either True or False. So, to turn this into a 0,1,2:

      Dim iSync1 as Integer
          If optSync1(0) then
              iSync1 = 0
          ElseIf optSync1(1) then
              iSync1  = 1
          Else
              iSync1 = 2
          EndIf

      You probably noticed that I didn’t use the .Value: Value is the default property, so I can leave it out. I also assumed that you had exactly 3 option buttons and one of them had been set true during design. Hope this helps! –Sam

      • #547343

        Thanks for the info. You confirmed that option buttons work differently in VB than in Access, so I know that I wasn’t overlooking something.

        You are right about the control names, and I usually follow your method. Was getting very frustrated with the differences between VB and Access, and had to create and delete the controls several times. Got lazy…. But I am feeling much better now dizzy

        • #547445

          Jack, I felt the same way drop when I did some Access programming, but ended up liking Access features better. Sorry that you have to downgrade to VB. –Sam

          • #547589

            I agree, Sam. I started out with Access and had a terrible time with VB because you have to work SO hard to do things like populate a combobox or worse, to handle the items selected in a combo or listbox. I balk at any serious work with databases in VB because the functionality just isn’t there for forms, controls and reports. Maybe someday. shrug

            • #547814

              Gee — it’s kinda reassuring to know that I’m not alone. I’ve read a lot about VB and its power, but most of my experience has been with Access. I am always spinning my wheels with VB — thought that it was just me. Glad (???) to see that someone with Charlotte’s depth of knowledge is similarly befuddled.

    Viewing 0 reply threads
    Reply To: Confused about control arrays (VB5)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: