check box's & if else statements

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

check box's & if else statements

Post by KennyR » Fri Jan 20, 2012 5:42 pm

I was curious, can you structure an "if then/else" statement to trigger two different commands in a check box script? Example....I have code that puts the "label of me"(checkbox) into a field on another card. I would like to be able to remove the label when a user "uncheck's" the box. So far, all my attempts have failed!!!

edit- better yet...what is the best way to remove a string of text if the user de-selects the check box?

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: check box's & if else statements

Post by Klaus » Fri Jan 20, 2012 5:51 pm

Hi Kenny,

that's pretty easy: You can check "the hilite of btn xyz".

Code: Select all

...
if the hilite of btn "your checkbox here..." then
   ## You can omit the = TRUE here!
   ## In that case the engine always presumes you mean TRUE :-)

   ## checkbox checked!
   ## do your stuff
else
  ## checkbox UNchecked
  ## do other stuff here...
end if
...
Best

Klaus

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: check box's & if else statements

Post by KennyR » Fri Jan 20, 2012 6:08 pm

Thank you for the quick response! Much KUDOS!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: check box's & if else statements

Post by KennyR » Fri Jan 20, 2012 7:34 pm

I feel like a complete idiot...I cannot for the life of me delete the entry after it has been placed in the field and the box is unchecked....I want to do something like this....

Code: Select all

on mouseUp
   

   if the hilite of button "v" then
      
     put label of me into fld "total" card "Finish"
   else
Delete label of me from fld "total" card "Finish"
   end if
   
end mouseUp
     
but the "Delete" portion of the code gives me an error after "from"
any suggestions?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: check box's & if else statements

Post by dunbarx » Fri Jan 20, 2012 8:04 pm

Hi.

Just a little more experience with LC syntax and you should be OK.

You don't empty the text of a field by deleting anything. If you want to empty a field:

put empty into field "total" of card "finish".

You are always putting; here you are just putting nothing.

This is no different than your earlier command to "put the label of me into field "total" of card "finish".

Craig Newman

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: check box's & if else statements

Post by jmburnod » Fri Jan 20, 2012 8:05 pm

Hi Kenny,

You can't delete a lavel. Only set it
But if you want empty in fld card "Finish you can try

Code: Select all

on mouseUp
   if the hilite of button "v" then
      put label of me into fld "total" of card "Finish"
   else
      put empty into fld "total" of card "Finish" -- empty or what you want
   end if
end mouseUp
Best regards

Jean-Marc
https://alternatic.ch

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: check box's & if else statements

Post by KennyR » Fri Jan 20, 2012 8:10 pm

thanks so much everyone! I love that we have a friendly forum to ask questions....

Post Reply