Welcome, Guest. Please Login
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
Pages: 1
Send Topic Print
Combining if() clauses (Read 2752 times)
Rhonda Boorman
Full Member

Posts: 3

Combining if() clauses
Oct 2nd, 2012, 6:54pm
(By Admin) I'm going to split your last reply in "Re: Action to change note title colour" and mine to it into a new thread. Despite both topics arising from your work, they are unrelated as forum topics. Having them separate keeps things clearer and makes it easier for others searching the forum for previously answered topics.

Thanks for your clear explanations.

My next lesson in coding.....

I created a user attribute called PhD, data type boolean.  I wanted all notes checked as PhD to be bright red.  I want all notes to change to grey when 'Checked' is ticked.  I also want the notes to revert to correct color if a ticked box is subsequently unticked (the else code I believe).

This code does not change PhD ticked notes to red, but does change Checked ticked notes to grey.
if($PhD) {$Color="bright red"};
if($Checked) {$Color="grey"} else {$Color="black"};

I thought the else function was overriding the PhD code so I removed that bit (else {$Color="black"}) and it worked.  However, notes will not restore to original color (black) if the ticked boxes (Checked or Phd) are unticked.  

My question is, how do I include the 'else' code for a sequence of events?  I.e. if Checked is unticked revert to black, unless PhD is ticked in which case revert to red.
Back to top
« Last Edit: Oct 03rd, 2012, 3:40am by Mark Anderson »  
  IP Logged
Mark Anderson
YaBB Administrator

User - not staff!

Posts: 5689
Southsea, UK
Re: Action to change note title colour
Reply #1 - Oct 3rd, 2012, 3:37am
Well, a note can only be one color. Your code's logic has one if() set a note bright red but never resets it. A completely separate if() clause sets a note to grey or black. Thus, each time the rule runs:

A $PhD and $Checked note is grey
A $PhD-only note is black (the else part of the second if()
A $Checked-only is grey
A note with neither $PhD and $Checked is black

You need to put the second if() in the else() branch of the first. Try the following, which I've split onto several lines for clarity:

if($PhD) {
  $Color="bright red"
} else {
  if($Checked) {
  } else {

Now, each time the rule runs:
A note both $PhD and $Checked note is bright red
A $PhD-only note is bright red
A $Checked-only is grey
A note with neither $PhD and $Checked is black

  • If $PhD is ticked, the note is set to bright red and none of the rest of the code is evaluated.
  • If $PhD is false, the if() in the else branch of the first if is evaluated.
  • If $PhD is false, a note is set to grey or black depending on the state of $Checked.
If you want a note to be grey instead of bright red when both Booleans are ticked, reverse the positions of the tests for each, i.e. test for $Checked in the first if() and $PhD in the second.
Back to top
« Last Edit: Oct 3rd, 2012, 3:39am by Mark Anderson »  

Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print