[Gambas-user] Hope I'm doing this correctly - I'm searching for help to reference a control using a variable

Gianluigi bagonergi at gmail.com
Thu Mar 22 19:24:52 CET 2018


Hi Charlie and Lee,
he later wrote me this privately:
See [0]
and I showed him the use of 'Last' [1]
But I also added, in my bad English, that I would no longer answer
privately as the mailing lists are useful to everyone, I hope he was not
offended.
I can also add the use of code like this:

  Dim c As Control

  If Object.Is(c, "Label") Then c.Foreground = Color.Red

  ...

  Dim c As Control

  For Each c In FMain.Controls

    If c.Name Like "Label{2,3,4,5,6,7,8,9,10,11,12,13}" Then
      c.Foreground = Color.Red
    Endif

  Next

...

[0] [I don't want to address them as "Label1", etc.  I do not know until
runtime which of 75 labels that I need to update.  I would prefer not to
get anywhere near some big case statement based on the value of the
integer.  So instead of addressing them as Label1, Label2, etc., I need to
be able to access them as, for example, Labelx where the "x" is a
variable.  There would not be a label with the name of "Labelx".  This part
of a Bingo calling program I wrote if VB and want to convert to Gambas.  If
you would like to see a snippet of the VB code doing this just let me know.
Thanks again.]

[1] http://gambaswiki.org/wiki/lang/last

Regards
Gianluigi

2018-03-22 18:01 GMT+01:00 T Lee Davidson <t.lee.davidson at gmail.com>:

> Yes, you're posting to the correct list.
>
> You will find Gambas documentation at http://gambaswiki.org/wiki .
>
> From there, you can go to Components under Language Reference. Then look
> under Graphical User Interface.
>
> You will probably use the docs for gb.qt4 and gb.form (enhanced controls)
> for most things GUI.
>
>
> --
> Lee
>
>
> On 03/22/2018 12:07 AM, David Eaton via User wrote:
> > I'm new to this mailing list idea - I don't know how they work or if I'm
> posting into the correct one.
> >
> > I am looking for some help in programming with Gambas.  In particular, I
> have a program that has several label controls.  I need
> > to be able to set properties on these labels via a variable - similar to
> this pseudo code:
> >
> > dim stringx as string = ""
> > dim myint as integer = 1
> >
> > myint = somenumber_determined_at_runtime
> > stringx = "Label" & myint
> > Stringx.propertiy = somevalue_determined_at_runtime
> >
> > I was able to do this in Visual Basic following some samples on the
> internet.
> >
> > Is there a way to do this in Gambas?
> >
> > Thank you, and if I have put this in the completely wrong place please
> let me know.
>
> --------------------------------------------------
>
> This is the Gambas Mailing List:
> https://lists.gambas-basic.org/listinfo/user
>
> Search the list:
> https://lists.gambas-basic.org/cgi-bin/search.cgi
>
> Hosted by https://www.hostsharing.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180322/3e8b9208/attachment.html>


More information about the User mailing list