Results 1 to 5 of 5

Thread: Common event for an array of controls?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112

    Question

    Aquiring new knownledge about creating controls at run time, I would like to them to share a common event-procedure.

    Does anyone know how to do this? Look at my pseudo to see what I'm looking for.

    Code:
    Dim myControls(100) As objects
    
    Sub MakeTheControls()
      Set myControls(0) = Controls.Add(...)
      Set myControls(1) = Controls.Add(...)
      ...
    End Sub
    
    Sub CommonEvent(AString As String)
      'AString is an identifier that i can use in the following:
      Select Case AString
        Case "my1stcontrol": ...
        Case "my2ndcontrol": ...
        ...
      End Select
    End Sub






  2. #2
    Member
    Join Date
    Jan 1999
    Location
    Longmont,CO
    Posts
    53

    Talking

    What you're talking about is a control array. Control arrays share the same event procedure:

    Sub Control_Click(Index as Integer)
    'Test for which control was clicked by its index
    End Sub

    I beleive that you have to add 1 control at design time and then use the 'Load' statement at run time. I don't have a good example to show you, but I know it's on my computer somewhere. If I find it, I'll email it to you.

    Hope this helps,

    Dan


  3. #3
    Guest
    Here's an example. Make a Contrtol called MyControl and place the following code into a CommandButton. Make sure that the Index property to MyControl is set to 0.

    Code:
    Load MyControl(1)
    MyControl(1).Move 0, 0
    MyControl(I).Visible = True

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Norway
    Posts
    112
    You don't by any way know how to create an control array in VBA, do you? You can't do it the way you do it in VB5/6. If you can at all.

  5. #5
    Guest
    No, I don't think that method would work in VBA.

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