[Gambas-user] How to create an array of checkbox?

Gianluigi gradobag at gradobag.it
Mon Sep 25 23:59:47 CEST 2023


Il 25/09/23 23:32, vuott--- via User ha scritto:
>
> You can also directly use an array of "CheckBox":    CheckBox[...]
>
> You can also avoid using an array, though:
>
> [code]
> Public Sub Form_Open()
>
>   Dim cb As CheckBox
>
>   For b As Byte = 0 To 3
>     With cb = New CheckBox(Me) As "CheckCheck"
>       .X = (b + 1) * 50
>       .Y = 100
>       .W = 20
>       .H = 10
>       .Name = "CheckBox n. " & CStr(b)
>     End With
>   Next
>
> End
>
> Public Sub CheckCheck_MouseDown()
>
>   Print Last.Name
>
> End
> [/code]
>
>
>
> 25 set 2023, 21:18 da roberto.premoli at tiscali.it:
>
>     Il 25.09.2023 20:11 T Lee Davidson ha scritto:
>
>         On 9/25/23 13:53, roberto.premoli at tiscali.it [1]wrote:
>
>             Hello,i using checbox, 16 checboxez, form check01 to
>             check16. i manage
>             it individually position, value, text, etc. Now program
>             need to be
>             expandedto 64 (maybe 128 in future) checkbox. To hndle
>             manually is a
>             pain, with high risk to do human misake in copy/paste of
>             code. I need
>             an array like check(index 0 to 63). I know is not possible
>             to do in
>             IDE, but i dont know ho tto do in code. I tied to search
>             in gambaswiki
>             without find so i came here to ask. A little example will
>             be greatly
>             apprecated howto create an array of checkbox. thanks, Roberto
>
>
>         Maybe Object[] will do what you need:
>         https://gambaswiki.org/wiki/comp/gb/object[] [2]
>
>         -- Lee ----[ http://gambaswiki.org/wiki/doc/netiquette [3] ]----
>
>
>
>     Links:
>     ------
>     [1] mailto:roberto.premoli at tiscali.it
>     [2] https://gambaswiki.org/wiki/comp/gb/object[]
>     [3] http://gambaswiki.org/wiki/doc/netiquette
>
>
>     it works, craete an array of check box. but now how can i interact
>     with that? if i draw a checbbox in code, then i have therlative
>     action (mousedown, etc) that i can fill with my code , bit with
>     this dinamically created objec,s where can i wrote te relative cod
>     tu react to actions on them?
>
>
>     ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
>
>
> ----[http://gambaswiki.org/wiki/doc/netiquette  ]----

Yes, I agree with vuott and I would write the code as follows:

-------------------------------------------

Private hCheck As CheckBox

Public Sub Form_Open()

   Dim hScroll As ScrollView

   With Me
     .Arrangement = Arrange.Fill
     .W = 200
     .h = 500
   End With
   With hScroll = New ScrollView(Me)
     .ScrollBar = Scroll.Vertical
     .Arrangement = Arrange.Vertical
   End With
   For i As Integer = 0 To 63
     With hCheck = New CheckBox(hScroll) As "Check"
       .Name = "CheckBox" & CStr(i + 1)
       .Text = "CheckBox " & CStr(i + 1)
     End With
   Next

End

Public Sub Check_Click()

   Print Last.Name;; Last.value

End

------------------------------------------

Regards

Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230925/ea040bba/attachment-0001.htm>


More information about the User mailing list