Re: Referring to controls via loops - comments and suggestions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



In message <#mqAQdZRFHA.2132@xxxxxxxxxxxxxxxxxxxx>, Steve Le Monnier <steve_lemon@xxxxxxxxxxxxxxxxxxxxxxxxx> writes

What is it that you are trying to achieve by this? There may be another
approach.


I was trying to reduce the amount of code to write when preparing the
controls and they all need to behave the same way, hence tryin to refer to
each one via a loop.

I know this isn't the in thing to say, but VB6 allowed you to append strings
to the end of a control and then evaluate the entire statement as a command
line and not text.

That said, I have found a better way of doing it and that is loading all my
controls into an array and then referencing them via the array e.g.

_lnkCostCenters[0] = this.lnkCostCentre1;

_lnkCostCenters[1] = this.lnkCostCentre2;

_lnkCostCenters[2] = this.lnkCostCentre3;

for ( int i = 0; i < _controlCount; i++ )

{

_lnkCostCenters[i].Text = "Department";

}

Ah, I see. You could always subclass the control.

--
Steve Walker
.



Relevant Pages

  • Re: Array question
    ... Thanks for catching my syntax error (fields and controls). ... using the tag property to loop through all the fields but thought that the ... idea of a "simulated control array" which I found in a Microsoft KB seemed ... Dim ctl As Control ...
    (microsoft.public.access.modulesdaovba)
  • Re: Array question
    ... other elements in the array looking for duplicates. ... loop starts with the first element and loops through all the ... Or, for less coding, you can use the Tag property of your controls and enter ... Dim ctl As Control ...
    (microsoft.public.access.modulesdaovba)
  • Re: Continuous Subforms
    ... there is not multiple instances of the controls. ... you can't really reference the controls like an array. ... the "general" program loop to process a reocrdset is: ...
    (microsoft.public.access.forms)
  • Control Arrays in ASP.Net
    ... in VB6, I used to be able to create an array of controls: ... That way, I could do a for/next loop and run through them with code, using ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Looping through controls....
    ... controls putting them into an array, and sort the array with the Sort method ... controls and return the comparison, ... >I need to loop through a bunch of textbox controls on my form. ...
    (microsoft.public.dotnet.languages.vb)