How do I tick a check box through code?

mistermentality

Active Member
Licensed User
Longtime User
I have a check box that I need to tick or untick based on a users saved preferences read from a map but cannot seem to figure it out.

I have tried
B4X:
If Map1.Get("autosearch") = "True" Then CheckBox1_autosearchnet.Checked

Where CheckBox1_autosearchnet is the check box name.Have tried other variations too such as

B4X:
If Map1.Get("autosearch") = "True" Then CheckBox1_autosearchnet.Checked = True

but without success. Unfortunately I am still new to B4A and never used a language that had check boxes before so can someone please tell me what I have done wrong?

Thanks.

Dave
 

kickaha

Well-Known Member
Licensed User
Longtime User
I just added a checkbox called Checkbox1 to my test program, and put
B4X:
Checkbox1.Checked = Not (Checkbox1.Checked)
in a button_Click event and it worked just fine - everytime I clicked the button the checkbox changed state.

There must be something else going on in your code - I would suspect that the Map1.Get("autosearch") is not returning the value you think it is.
Do you get an error or does it just not work.

Oh, and not to forget
B4X:
Dim CheckBox1 As CheckBox
in Globals.
 
Last edited:
Upvote 0

mistermentality

Active Member
Licensed User
Longtime User
There must be something else going on in your code - I would suspect that the Map1.Get("autosearch") is not returning the value you think it is.

Thank you

I don't know why but the variables stored are Booleans and so either True or False yet were stored in lower case. I was checking for "True" not "true".

Changed it to save not the Boolean value but "enabled" or "disabled" and that turned out to be the problem.

Dave
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…