Toggle button .checked = true

barx

Well-Known Member
Licensed User
Longtime User
Hi

Can anybody explain this strange behaviour.

I am saving a record for a database I use

B4X:
Record.Put("sound", toggleSound.Checked)

When i paused on this line it shows that toggleSound.Checked = true

Yet when I read the field from database I get an error because the field = 1 Which cannot parse to true or false.

I know I can parse it myself but why does it show as true/false in ide on pause yet save in database as 1/0.

Database field is a BOOL btw

thanks
 

barx

Well-Known Member
Licensed User
Longtime User
Ah, I see. Never noticed that. Sure I have manually set true / false before and worked ok. Though I can't have if it doesn't support it. Lol

Guess its time for my int2bool lib to make an appearance.

Thanks for reply

Sent from my HTC Desire Z
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
OK, done a little more investigating and found this...

if I wrap the true/false in ' ' it will save as true false. If I don't it saves as 0 / 1.

Does this mean that even though it type is set to Bool (in SQLManager) it is saving as text?
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
Does this mean that even though it type is set to Bool (in SQLManager) it is saving as text?
Yes.

See Sqlite documentation here:
Datatypes In SQLite Version 3




Rolf
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
OK, I had this working and for some reason now it's not and I cannot get it right again.

I'm trying to save the state of a toggle button in a sqlite db and later read / update it also.

what would be the best way of doing this?
 
Upvote 0

rbsoft

Active Member
Licensed User
Longtime User
I personally save true/false in an Sqlite db as numerical value:
False = 0
True = 1 (or any nonzero value. Some languages also assign -1 to True).

B4X:
If value = 0 Then
  toggleSound.Checked = false
else
  toggleSound.Checked = true
End if

Rolf
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Ok going to try that, see if things settle down.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…