Control arrays

Discussion in 'AutoCAD' started by Matt W, Sep 13, 2004.

  1. Matt W

    Matt W Guest

    In VB you can do something like this...

    Dim I as Integer
    For I = 1 to 5
    Label(I).Caption = "This is Label " & I
    Next I

    Is there a workaround for this for VBA??
     
    Matt W, Sep 13, 2004
    #1
  2. Matt W

    Joe Sutphin Guest

    No
     
    Joe Sutphin, Sep 13, 2004
    #2
  3. Matt W

    Matt W Guest

    That's not the answer I was looking/hoping for.

    Thanks, Joe!

    --
    I love deadlines
    I like the whooshing sound they make as they fly by.

    | No
    |
    | | > In VB you can do something like this...
    | >
    | > Dim I as Integer
    | > For I = 1 to 5
    | > Label(I).Caption = "This is Label " & I
    | > Next I
    | >
    | > Is there a workaround for this for VBA??
    | >
    | > --
    | > I love deadlines
    | > I like the whooshing sound they make as they fly by.
    | >
    | >
    | >
    |
    |
     
    Matt W, Sep 13, 2004
    #3
  4. Matt W

    Ed Jobe Guest

    I came up with one. I combined the index with the name. I use it to create
    textboxes on the fly, depending upond how many ents are selected. For an
    example, download my TextUtilities at
    http://www.augi.com/exchange/default.asp. Look at the TextMult procedure.
     
    Ed Jobe, Sep 13, 2004
    #4
  5. VBA lets you iterate the controls in a form.

    If you use a stock name combined with an index, you can reference a set
    of controls:

    For i = 1 to 5

    Set tbox = Me.Controls("TextBox" + i)
    ' Do your thing

    Next
     
    Frank Oquendo, Sep 13, 2004
    #5
  6. Matt W

    Ed Jobe Guest

    That's basically what I was doing.
     
    Ed Jobe, Sep 13, 2004
    #6
  7. Matt W

    Matt W Guest

    Thanks, Frank!
    Do you have any idea why this won't work with Cyrille Fauvel's SLIDE.OCX??

    Here's what I've got....

    Dim ctlSlide As Slide.Slide
    Dim intSlide As Integer

    For intSlide = 1 To 6
    Set ctlSlide = Me.Controls("Slide" + intSlide) ' It bombs out here
    with a type mismatch error.
    ctlSlide.FileName = "E:\Test(intSlide)"
    Next intSlide

    --
    I love deadlines
    I like the whooshing sound they make as they fly by.

    | Matt W wrote:
    |
    | > Is there a workaround for this for VBA??
    |
    | VBA lets you iterate the controls in a form.
    |
    | If you use a stock name combined with an index, you can reference a set
    | of controls:
    |
    | For i = 1 to 5
    |
    | Set tbox = Me.Controls("TextBox" + i)
    | ' Do your thing
    |
    | Next
    |
    | --
    | There are 10 kinds of people: those who understand binary and those who
    | don't.
     
    Matt W, Sep 13, 2004
    #7
  8. Matt W

    bcoward Guest

    Matt,

    If your not using the Tag property that can be your solution.

    For Each LabelControl

    Select Case LabelControl.Tag

    Case "1"

    Case "2"

    End Select

    Next

    Regards,

    Bob Coward
    CADS, Inc

     
    bcoward, Sep 13, 2004
    #8
  9. Declare ctlSlide as Object and see what you get. With intrinsic
    controls, I've always used a variable of type Control.
     
    Frank Oquendo, Sep 13, 2004
    #9
  10. Dim objControl As msforms.Control 'Microsoft Forms 2.0 Object Library
    For Each objControl In UserForm1.Controls

    Next objControl
     
    Nathan Taylor, Sep 14, 2004
    #10
  11. Matt W

    Matt W Guest

    I found out what was going wrong...
    Seems VBA doesn't like the '+' symbol.

    When I changed it to '&', everything worked just fine using the code below:

    Dim ctlSlide As Slide.Slide
    Dim intSlide As Integer

    For intSlide = 1 To 6
    Set ctlSlide = Me.Controls("Slide" & intSlide)
    ctlSlide.FileName = "E:\Test.slb(intSlide)"
    Next intSlide

    Thanks for the help guys!
    Very much appreciated.

    Matt
     
    Matt W, Sep 14, 2004
    #11
  12. Matt W

    Ed Jobe Guest

    That will iterate through *every* control on the form. A control array is a
    method of grouping just a few controls, like some text boxes. In that case
    you wouldn't want the iteration to include labels and buttons.
     
    Ed Jobe, Sep 14, 2004
    #12
  13. Yes I was lazy it was a simple example of how to iterate controls on a form. You would obviously need to check if it is a control you are interested in. Also if the controls are in a frame you can iterate the frames control collection.
    Regards - Nathan
     
    Nathan Taylor, Sep 15, 2004
    #13
  14. Seems VBA doesn't like the '+' symbol.

    It's not that it doesn't like the + sign
    it's just that the + will concatenate strings only
    The & will convert your integer intSlide into a string and then concatenate.
     
    Jorge Jimenez, Sep 16, 2004
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.