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

vuott at tutanota.com vuott at tutanota.com
Tue Sep 26 08:37:25 CEST 2023


Robe'... you have to make them "Children" of the "Panel":

   With ccbb[b] = New CheckBox(Panel1) As "CheckCheck"





26 set 2023, 08:15 da roberto.premoli at tiscali.it:

> AND HERE WE ARE!
> this is exactly was I was looking for! thank you and to all who helped me.
> JUST LAST QUESTION: this code create the array and wrote them into the main window, the Form.
> In my actual code the list of single checkbox are inside a panel (so if i move the panel, i move all the object inside and make it more easy for me to arrange his position around the main window, the Form).
> So, it is possible to create those ccbb[index] inside Panel1 and if yes, how?
>
>
> Il 26.09.2023 02:09 vuott--- via User ha scritto:
>
>
>> ...now let's do an analogous example, but with checkbox array:
>> [code]
>> Private ccbb As New CheckBox[4]
>> Public Sub Form_Open()
>>   
>>   For b As Byte = 0 To 3
>>     With ccbb[b] = New CheckBox(Me) As "CheckCheck"
>>       .X = (b + 1) * 70
>>       .Y = 100
>>       .W = 50
>>       .H = 10
>>       .Name = "CheckBox n. " & CStr(b)
>>     End With
>>   Next
>>  
>> End
>> Public Sub CheckCheck_MouseDown()
>>  
>>   Print Last.Name
>>  
>> End
>> Public Sub Button1_Click()
>>   ccbb[2].Background = Color.Red
>> End
>> [/code]
>> 26 set 2023, 02:03 da user at lists.gambas-basic.org:
>>
>>>
>>> I did not use an array.
>>>
>>> With my code you have to identify a feature, more specifically a Property that identifies the graphic Object, whose background color you want to change.
>>> Example:
>>> [code]
>>> Private cb As CheckBox
>>> Public Sub Form_Open()
>>>   
>>>   For b As Byte = 0 To 3
>>>     With cb = New CheckBox(Me) As "CheckCheck"
>>>       .X = (b + 1) * 70
>>>       .Y = 100
>>>       .W = 50
>>>       .H = 10
>>>       .Name = "CheckBox n. " & CStr(b)
>>>     End With
>>>   Next
>>>  
>>> End
>>> Public Sub CheckCheck_MouseDown()
>>>  
>>>   Print Last.Name
>>>  
>>> End
>>> Public Sub Button1_Click()
>>>   Dim ob As Object
>>>   For Each ob In Me.Children
>>> ' Identify the name of the first "CheckBox" and changes its background color:
>>>     If ob.Name = "CheckBox n. 0" Then ob.Background = Color.Red
>>>   Next
>>> End
>>> 26 set 2023, 00:18 da roberto.premoli at tiscali.it:
>>>
>>>> done, but now i have another problem: how can I address the single element of array?
>>>> for example if i want to chance some value of a precise element of array, for example background, like this:
>>>> public sub button1_Mousedown()
>>>>   CheckCheck[2].background = 255
>>>> end
>>>>
>>>>  
>>>>
>>>> it return me the follow error "unknown identifier: CheckCheck".
>>>> probably i do wrong sintax but i dont know the right one
>>>> Il 25.09.2023 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 ]----
>>>>>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230926/a5aaec95/attachment.htm>


More information about the User mailing list