[Gambas-user] Check Boxes (a bug?)

John Dovey dovey.john at gmail.com
Sat Jun 12 01:10:09 CEST 2021


Never mind. Found it.
Changed the line
If myFlag Then myAflagsString.Add(myAflags.Key)
to
If myFlag = -1 Then myAflagsString.Add(myAflags.Key)

---
Public Sub AflagsGroup_Click()

    Dim myAflagsString As New String[]

    myAflags[Last.Tag] = Last.Value ' We set the value only on the flag
that changed and do not mess with the others.
    For Each myFlag As String In myAflags
        Debug ("myFlag:" & myFlag & ":" & myAflags.Key)
        If myFlag = -1 Then myAflagsString.Add(myAflags.Key)
    Next
    LblAflags.Text = myAflagsString.Join(",")
    Debug ("LblAflags: " & LblAflags.Text)

End
---


On Fri, 11 Jun 2021 at 18:00, John Dovey <dovey.john at gmail.com> wrote:

> One more question:
> In the subroutine:
> Public Sub AflagsGroup_Click()
>
>     Dim myAflagsString As New String[]
>
>     myAflags[Last.Tag] = Last.Value ' We set the value only on the flag
> that changed and do not mess with the others.
>     For Each myFlag As String In myAflags
>         If myFlag Then myAflagsString.Add(myAflags.Key)
>     Next
>     LblAflags.Text = myAflagsString.Join(",")
>
> End
>
> My understanding is it runs through all the myAflags and adds all the
> occurrences that are checked. If that's the case, then I don't understand
> why it's not "removing" previously checked (and now unchecked) items?
>
> Thanks for all your assistance!!
> JD
>
>
> On Fri, 11 Jun 2021 at 14:34, T Lee Davidson <t.lee.davidson at gmail.com>
> wrote:
>
>> On 6/11/21 1:20 PM, John Dovey wrote:
>> > Thank you, That's helpful.
>> > Now to make it work...
>> >
>> > Just one quick comment. I pasted your code with the
>> "CheckBoxGroup_Click()" subroutine, but I named the group 'AflagsGroup". It
>> > took me a few minutes to figure out why it wasn't working. There was no
>> error that there was no such event :-)
>>
>> Ah, my bad. Please change the declaration for myAflagsString to:
>> Dim myAflagsString As New String[]
>>
>> Scalars and strings are automatically instantiated while arrays and
>> collections are not (unless a definition is provided with
>> the declaration using the "=" operator).
>>
>>
>> And also, in the Form_Open event, uncomment lines 123-126 and change them
>> to:
>>      ChkAflag_CM.Value = myAflags["CM"]
>>      ChkAflag_MO.Value = myAflags["MO"]
>>      ChkAflag_LO.Value = myAflags["LO"]
>>      ChkAflag_ICM.Value = myAflags["ICM"]
>>
>> This will set the status of each checkbox appropriately.
>>
>>
>> --
>> Lee
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210611/be24cf5a/attachment-0001.htm>


More information about the User mailing list