[Gambas-user] how to write text in indexed list of labels

Tony Morehen tmorehen at ajm-software.com
Mon Sep 7 16:03:15 CEST 2020


An alternative approach, which is particularly useful if the labels are 
dynamically placed on the form,  would be to use a global array of labels:

In the globals area of the form class:

     Private theArrayOfLabels as Collection

In the form setup method (say form_open):

     theArrayOfLabels = New Label[]
     Dim lbl as Label

     For each index as Integer = 0 to 199
         lbl = new Label(parent)  'parent could be Me or some other 
container
         'code to setup the new label (initial text, font, foreground, 
width  etc)
         'you don't need to set the name
         theArrayOfLabels.Add(lbl)
     Next

Finally where you reset the label text:

     theArrayofLabels[index].Text = "new text"

Instead of an array of labels, you could use a collection of labels, 
with the key being the individual label's name.




On 2020-09-06 10:58 a.m., pinglix via User wrote:
>
> Hi,
>
> I have 200 Label components on a form with name Label1, Label2 .... 
> Label200 and I need to change the Text property of one of them through 
> an integer index.
>
>
> What is the best way to do it ?
>
> I cannot find a Find() method by name that returns a reference to the 
> correct object.
>
> I can set them to the same Group but then what can I do with it ?
>
>
> Thanks,
>
> Paolo
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20200907/ed4c8f9d/attachment.htm>


More information about the User mailing list