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

pflora at libero.it pflora at libero.it
Mon Sep 7 17:18:19 CEST 2020


Thank you to everybody.

As I am not fond in gambas language I used the solution:


Dim hlabel As Label

Dim idName as String

Dim idx as Integer

idx = ..... some integer value

idName = "Label" & idx


hlabel = Me[idName]


If hlabel <> Null Then hlabel.Text = " my string"


The above works good, I write to all 200 labels some messages indexed from UDP datagrams.


>     Il 07/09/2020 16:03 Tony Morehen <tmorehen at ajm-software.com> ha scritto:
> 
> 
> 
>     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 ]----
> > 
> >     >     ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20200907/24e21c7a/attachment-0001.htm>


More information about the User mailing list