Capturing checkbox activity

Post

Posted
Rating:
#1 (In Topic #1079)
Trainee
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

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!
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
You got the _Click event right but not your operators.

In gambas 2 equal signs == is ONLY used for "case insensitive string comparisons"
/cat/stringop - Gambas Documentation

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

try it using only one = sign

Code (gambas)

  1. Public Sub DCAllStats_Click()
  2.   If DCAllStats.Value = True Then
  3.     Message("True")
  4.   If DCAllStats.Value = False Then
  5.     Message("False")
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
Thank you! Serves me right for assuming!
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’

Thagn said

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 :)
Online now: No Back to the top

Post

Posted
Rating:
#5
Regular
vuott is in the usergroup ‘Regular’

Thagn said

Code

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:

Code (gambas)

  1. Public Sub DCAllStats_Click()
  2.  
  3.   If DCAllStats.Value Then
  4.     Message("True")
  5.   Else
  6.     Message("False")
  7.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top
1 guest and 0 members have just viewed this.