How To set the content of a check box button in a script

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

How To set the content of a check box button in a script

Post by phaworth » Sun Jul 12, 2009 10:15 pm

I guess the Subject says it all. I'm reading data from a database. Some of the fields are boolean True/False and I need to set the value of check box buttons in a script to contain the value from the database entry and I don;t see how to do this.

I have a combobox button and it seems that setting the label property of that to a field from the database record makes the correct value show up in the combobox. If I do that with a check box button, the label of the check box on the screen just gets set to the numeric value of true or false.

I've tried "put ..... into button "checkBox" and "set button checkBox to..." but the former seems to have no effect and the latter gives me an error.

The User Guide is silent on this, at least as far as I can find.

I'm sure there is some simple way of doing this!

Pete

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Sun Jul 12, 2009 10:31 pm

Hi phaworth,

how about:

set the label of button "myButton" to "myLabel"

?

regards
bernd

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Sun Jul 12, 2009 11:09 pm

Hi pete,

I guess you are interested into the hilite property. Set the hilite of btn "mycheckbox" to true / false

Hth,

Malte

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Mon Jul 13, 2009 12:46 am

Thanks, I think hilite is the answer, however now I have another problem.

The code I am using is:

Code: Select all

  set the hilite of button "Active" to revDatabaseColumnNamed(gRsetID,"Active")
This compiles OK but when it is executed, I get an error:

execution error at line n/a (Object: value is not a boolean (true or false)) near "0"

That last "0" is the value in the database field, which is always zero or 1. I think that's standard for databases (I'm using SQLite) but it seems that Revolution expects some other representation of true/false?

Pete

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon Jul 13, 2009 6:00 am

Hi Pete,

Revolution is not a 'typed' language, and doesn't interpret 0 as 'false' and 1 as 'true' - you really have to pass true or false when you need a boolean value.
You can put a 'generic' function in your stack script

Code: Select all

function SqlBoolean pSqlValue
  return (pSqlValue is 1)
end SqlBoolean
and ten use that in your script

Code: Select all

set the hilite of button "Active" to SqlBoolean (revDatabaseColumnNamed(gRsetID,"Active"))
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Mon Jul 13, 2009 6:20 am

Thanks Jan, figured I'd have to do something like that.

On a separate issue, I need to cycle though the names of all the objects on a card and do some processing on each object depending on what type of object it is. There's another post from someone who told me how to get a count of the number of objects so I can use that as a control for the repeat loop but not seeing how to get the name of each object (and other properties) based on the iteration of the repeat loop.

This is my attempt to get round the bug in the Database Query builder that stops it working properly with SQLite dbs. My plan is to name each object the same as the db field it is linked to then write some routines which will load the db info into the fields and also update the db when the fields are changed. Painful but a lot less work than writing code specific to each field.

Pete

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Post by phaworth » Mon Jul 13, 2009 6:35 am

Never mind - I think I figured it out.
Pete

Post Reply