+ Reply to Thread
Results 1 to 5 of 5

Control Index Numbers

Hybrid View

  1. #1
    Richard Buttrey
    Guest

    Control Index Numbers

    I have a frame containing a dozen or so check boxes.

    They've been added at various times and I've probably deleted some and
    added others.

    In some code I count the number of controls, and in a loop with say
    'x' as a loop counter, I test the tag property of the control(x). I've
    been having some problem with this and I now realise that what I
    believed to be say the 3rd checkbox, ( because I thought it was the
    third one I'd added), is actually recognised by VBA as say the 5th
    checkbox, (identified by the x counter). i.e. Controls(x)

    It seems clear that in all my additions and deletions, the system
    number of the control is different to what I think it is.

    My question is, is there any way of re-setting the system numbers of
    these controls so that they line up with the order in which they
    appear in the frame?

    An associated question. Is there any way of observing directly what
    the control number of a particular control is? I can obviously work it
    out indirectly by writing a bit of code which tells me say the Tag or
    Caption associated with a particular control, but it's not immediately
    apparent if the system number is a property of the control which can
    be viewed - and changed (in a similar way to the way in which the Tab
    property number can be changed).

    Rgds and usual TIA





    __
    Richard Buttrey
    Grappenhall, Cheshire, UK
    __________________________

  2. #2
    Bob Phillips
    Guest

    Re: Control Index Numbers

    AFAIK the index of the control is determined by the order in which the
    controls are added, and cannot be changed.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Richard Buttrey" <chaos.theory.nospam.removethis@zen.co.uk> wrote in
    message news:2l26g15lf1kc3hfsj5sttp6l7lnhqc2hio@4ax.com...
    > I have a frame containing a dozen or so check boxes.
    >
    > They've been added at various times and I've probably deleted some and
    > added others.
    >
    > In some code I count the number of controls, and in a loop with say
    > 'x' as a loop counter, I test the tag property of the control(x). I've
    > been having some problem with this and I now realise that what I
    > believed to be say the 3rd checkbox, ( because I thought it was the
    > third one I'd added), is actually recognised by VBA as say the 5th
    > checkbox, (identified by the x counter). i.e. Controls(x)
    >
    > It seems clear that in all my additions and deletions, the system
    > number of the control is different to what I think it is.
    >
    > My question is, is there any way of re-setting the system numbers of
    > these controls so that they line up with the order in which they
    > appear in the frame?
    >
    > An associated question. Is there any way of observing directly what
    > the control number of a particular control is? I can obviously work it
    > out indirectly by writing a bit of code which tells me say the Tag or
    > Caption associated with a particular control, but it's not immediately
    > apparent if the system number is a property of the control which can
    > be viewed - and changed (in a similar way to the way in which the Tab
    > property number can be changed).
    >
    > Rgds and usual TIA
    >
    >
    >
    >
    >
    > __
    > Richard Buttrey
    > Grappenhall, Cheshire, UK
    > __________________________




  3. #3
    Jean-Yves
    Guest

    Re: Control Index Numbers

    Hi Richard
    In general, it is better practice to rename the controls yourself and then
    adress the control by its name iso by index.
    another way is to create your controls at run time and record their name
    in an array.
    Regards
    Jean-Yves

    "Richard Buttrey" <chaos.theory.nospam.removethis@zen.co.uk> wrote in
    message news:2l26g15lf1kc3hfsj5sttp6l7lnhqc2hio@4ax.com...
    > I have a frame containing a dozen or so check boxes.
    >
    > They've been added at various times and I've probably deleted some and
    > added others.
    >
    > In some code I count the number of controls, and in a loop with say
    > 'x' as a loop counter, I test the tag property of the control(x). I've
    > been having some problem with this and I now realise that what I
    > believed to be say the 3rd checkbox, ( because I thought it was the
    > third one I'd added), is actually recognised by VBA as say the 5th
    > checkbox, (identified by the x counter). i.e. Controls(x)
    >
    > It seems clear that in all my additions and deletions, the system
    > number of the control is different to what I think it is.
    >
    > My question is, is there any way of re-setting the system numbers of
    > these controls so that they line up with the order in which they
    > appear in the frame?
    >
    > An associated question. Is there any way of observing directly what
    > the control number of a particular control is? I can obviously work it
    > out indirectly by writing a bit of code which tells me say the Tag or
    > Caption associated with a particular control, but it's not immediately
    > apparent if the system number is a property of the control which can
    > be viewed - and changed (in a similar way to the way in which the Tab
    > property number can be changed).
    >
    > Rgds and usual TIA
    >
    >
    >
    >
    >
    > __
    > Richard Buttrey
    > Grappenhall, Cheshire, UK
    > __________________________




  4. #4
    Richard Buttrey
    Guest

    Re: Control Index Numbers

    On Wed, 17 Aug 2005 14:44:22 +0200, "Jean-Yves"
    <nomail_I_hate_spam@spam.com> wrote:

    >Hi Richard
    >In general, it is better practice to rename the controls yourself and then
    >adress the control by its name iso by index.
    >another way is to create your controls at run time and record their name
    >in an array.
    >Regards
    >Jean-Yves



    Thanks Jean, (and Bob earlier),

    The only reason I was using the index number was that I did domething
    different with the first eight listed checkboxes than with the rest. I
    was using a simple Select statement assuming I could rely on the
    control index number as the Select Case i.e. Case<8. I now see I can't
    and will follow the advice you suggest.

    Incidentally, is it possible to see a control index number directly,
    or can this only be done by writing a bit of code to identify the
    control name of each control index number?

    Incidentally2. Are control index numbers always base zero?

    Rgds
    __
    Richard Buttrey
    Grappenhall, Cheshire, UK
    __________________________

  5. #5
    Jean-Yves
    Guest

    Re: Control Index Numbers

    Hi Richard,

    from help

    Controls Collection


    Includes all the controls contained in an object.





    Remarks

    Each control in the Controls collection of an object has a unique index
    whose value can be either an integer or a string. The index value for the
    first control in a collection is 0; the value for the second control is 1,
    and so on. This value indicates the order in which controls were added to
    the collection.

    If the index is a string, it represents the name of the control. The Name
    property of a control also specifies a control's name.

    You can use the Controls collection to enumerate or count individual
    controls, and to set their properties. For example, you can enumerate the
    Controls collection of a particular form and set the Height property of each
    control to a specified value.

    Note The For Each...Next statement is useful for enumerating a collection.

    You can use : MsgBox Me.Controls(0).Name, to see the first control that was
    created.

    Regards

    Jean-Yves





    "Richard Buttrey" <chaos.theory.nospam.removethis@zen.co.uk> wrote in
    message news:8iu8g1h5eg2i7dpec2b1kv262nni7p11gc@4ax.com...
    > On Wed, 17 Aug 2005 14:44:22 +0200, "Jean-Yves"
    > <nomail_I_hate_spam@spam.com> wrote:
    >
    > >Hi Richard
    > >In general, it is better practice to rename the controls yourself and

    then
    > >adress the control by its name iso by index.
    > >another way is to create your controls at run time and record their name
    > >in an array.
    > >Regards
    > >Jean-Yves

    >
    >
    > Thanks Jean, (and Bob earlier),
    >
    > The only reason I was using the index number was that I did domething
    > different with the first eight listed checkboxes than with the rest. I
    > was using a simple Select statement assuming I could rely on the
    > control index number as the Select Case i.e. Case<8. I now see I can't
    > and will follow the advice you suggest.
    >
    > Incidentally, is it possible to see a control index number directly,
    > or can this only be done by writing a bit of code to identify the
    > control name of each control index number?
    >
    > Incidentally2. Are control index numbers always base zero?
    >
    > Rgds
    > __
    > Richard Buttrey
    > Grappenhall, Cheshire, UK
    > __________________________









    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1