Capturing checkbox activity

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
Thagn
Posts: 2
Joined: Sunday 20th August 2023 4:31am

Capturing checkbox activity

Post by Thagn »

Hello,

I have a checkbox named DCAllStats that I am trying to do something with when a user changes the status of the checkbox. Looking at the associated events, it looked like click was the proper event, so I wrote the following code as a test:

Code: Select all

Public Sub DCAllStats_Click()
  If DCAllStats.Value == True Then
    Message("True")
  Endif
  If DCAllStats.Value == False Then 
    Message("False")
  Endif
End
Of course, clicking on the checkbox of DCAllStats doesn't trigger the Message. (In fact, clicking on the text doesn't work either) I wrote a separate bit of code to trigger when the form itself loads, and it works just fine. Any idea on what I'm doing wrong? One additional piece of information is that the checkbox is contained in a TabStrip if that makes any difference.

Thank you in advance!
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Capturing checkbox activity

Post by BruceSteers »

You got the _Click event right but not your operators.

In gambas 2 equal signs == is ONLY used for "case insensitive string comparisons"
http://gambaswiki.org/wiki/cat/stringop

So a "case insensitive string comparison" of 2 boolean values will always be False

try it using only one = sign

Public Sub DCAllStats_Click()
  If DCAllStats.Value = True Then
    Message("True")
  Endif
  If DCAllStats.Value = False Then 
    Message("False")
  Endif
End
If at first you don't succeed , try doing something differently.
BruceS
Thagn
Posts: 2
Joined: Sunday 20th August 2023 4:31am

Re: Capturing checkbox activity

Post by Thagn »

Thank you! Serves me right for assuming!
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Capturing checkbox activity

Post by BruceSteers »

Thagn wrote: Sunday 20th August 2023 12:46pm Thank you! Serves me right for assuming!
haha , what is it they say? to assume makes an ass of u and me :D

You're welcome :)

It's an easy mistake to make when you are used to another languages syntax.

I'd have a good read of the topics on this page Gambas wiki language overview Just to familiarize yourself of some differences in gambas to whatever you are used to.

We are always happy to help here too if you get stuck :)
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Capturing checkbox activity

Post by vuott »

Thagn wrote: Sunday 20th August 2023 4:38am

Code: Select all

Public Sub DCAllStats_Click()
  If DCAllStats.Value == True Then
    Message("True")
  Endif
  If DCAllStats.Value == False Then 
    Message("False")
  Endif
End
If you want, for the sake of brevity, you can do :? that as well:
Public Sub DCAllStats_Click()

  If DCAllStats.Value Then 
    Message("True")
  Else
    Message("False")
  Endif

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply