* Expression guidance please

Questions about creating, customising and using diagrams and charts
Post Reply
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Expression guidance please

Post by peterbel »

I want to add a icon to my Diagram Tree View, dependant upon the Birth OR Baptism place but all my expression attempts are rejected as "Expression not valid". For example, starting just with Birth:
ContainsText(%INDI.BIRT[1].PLAC>%,"Devon",FULL)

What should I be writing?
Thanks
Tracing the Devon Bellamy family along with their partners.
User avatar
tatewise
Megastar
Posts: 28435
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Expression guidance please

Post by tatewise »

FULL is not a valid 3rd parameter. Check the function Help page.

Also, the outermost function needs a leading = sign.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Re: Expression guidance please

Post by peterbel »

I am puzzled. I don't quite understand how ContainsText and = can work in the same expression. :?
None of the examples I have studied in the KB use it, but I am new to this.
Tracing the Devon Bellamy family along with their partners.
User avatar
tatewise
Megastar
Posts: 28435
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Expression guidance please

Post by tatewise »

See FHUG Knowledge Base Understanding Functions where the The Basics section explains where the = sign should and should not appear. The = sign indicates to the FH expression processor to expect a function name.

Your function should be:
=ContainsText( %INDI.BIRT[1].PLAC>%, "Devon", STD ) if it is NOT within the parentheses of another Function.
ContainsText( %INDI.BIRT[1].PLAC>%, "Devon", STD ) if is within the parentheses of another Function.
e.g. =TextIf( ContainsText( %INDI.BIRT[1].PLAC>%, "Devon", STD ), "Yes", "No" )

Understanding Expressions has many examples where functions have a leading = sign and many that do not for the reasons given above.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ADC65
Superstar
Posts: 472
Joined: 09 Jul 2007 10:27
Family Historian: V7

Re: Expression guidance please

Post by ADC65 »

You put the equals sign at the beginning of the expression, like this:

Code: Select all

=ContainsText(%INDI.BIRT[1].PLAC>%,"Devon",STD)
You can see some examples in the online help, here:

https://www.family-historian.co.uk/help ... stext.html

If you are using a function in an expression in a condition to display an Icon, you will need the equals sign. If you are just basing it on a fact, you won't need it, just the Data Reference. Have a look at some of the examples from my tree below:

Screenshot 2023-04-11 230554.jpg
Screenshot 2023-04-11 230554.jpg (50.63 KiB) Viewed 1152 times

Hope this helps. It can be a bit hit and miss while you develop complex expressions, just start simple and ask if you get stuck.

EDIT: Posted the same time as Mike, above, who explains it better :D
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
User avatar
AdrianBruce
Megastar
Posts: 2107
Joined: 09 Aug 2003 21:02
Family Historian: V7
Location: South Cheshire
Contact:

Re: Expression guidance please

Post by AdrianBruce »

One common misunderstanding is whether to include or exclude the leading = sign on the Function name.
  • If the Function is NOT within the parentheses of another Function then the = sign is required.
  • If the Function is within the parentheses then the = must be omitted.
My problem with the above is that it's just a recipe, and I'm not good at remembering recipes that I don't understand.

Can anyone explain why FH is happy with no = within parentheses, but needs a = outside? For instance
=CalcDate(Year(%INDI.BIRT.DATE%), 10)
doesn't have one on Year in that place - inside () - but CalcDate does need one? Is it to distinguish CalcDate from something else? Such as....?
Adrian
User avatar
tatewise
Megastar
Posts: 28435
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Expression guidance please

Post by tatewise »

Adrian, in some expressions (such as Sentence Templates, Diagram Text Schemes, and Report Heading Text) the items may be any of three types:
  1. Data Reference enclosed in %, e.g. %INDI.BIRT.DATE%
  2. Function starting with = sign, e.g. =CalcDate( ... )
  3. Plain text that can be anything.
It is necessary to have the % and = syntax to differentiate those three.
Otherwise INDI.BIRTH.DATE or CalcDate( ... ) would get taken as plain text.
When there is a syntax error, FH often displays parts of an expression in plain text when they are supposed to be Data References or Functions.

Inside the parentheses of a Function, the parameters that are plain text must be enclosed in single or double quotes.
Other parameters can be numbers or data references or functions which now don't need the = sign to differentiate them.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Re: Expression guidance please

Post by peterbel »

Thanks everyone. Forum replies always seem much easier to understand than reading the KB and the examples. :)

I am now struggling trying to add the OR operator to test if the both the Birth or Baptism place are in Devon.
I have tried to find the correct syntax for the expression and my several attempts have all been invalid, including this:
=ContainsText (%INDI.BIRT.PLAC>%,"Devon",STD) or ContainsText (%INDI.BAPM[1].PLAC>%,"Devon",STD)
Tracing the Devon Bellamy family along with their partners.
User avatar
tatewise
Megastar
Posts: 28435
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Expression guidance please

Post by tatewise »

Peter, if you inspect Understanding Expressions closely enough you will examples that are similar to your requirements involving or and and operators.
Clue: They all start with =IsTrue
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Re: Expression guidance please

Post by peterbel »

Thanks Mike. I hadn't realised the or had to pair with an IsTrue
Tracing the Devon Bellamy family along with their partners.
User avatar
AdrianBruce
Megastar
Posts: 2107
Joined: 09 Aug 2003 21:02
Family Historian: V7
Location: South Cheshire
Contact:

Re: Expression guidance please

Post by AdrianBruce »

tatewise wrote: 11 Apr 2023 23:00 Adrian, in some expressions (such as Sentence Templates, Diagram Text Schemes, and Report Heading Text) the items may be any of three types:
  1. Data Reference enclosed in %, e.g. %INDI.BIRT.DATE%
  2. Function starting with = sign, e.g. =CalcDate( ... )
  3. Plain text that can be anything.
Ah - thanks very much Mike. I think my analytical (or pedantic ;) ) mind was missing the "plain text" classification. Once you said that (which I suspect I was a long way from realising) then the three cases fall into place.
tatewise wrote: 11 Apr 2023 23:00 Inside the parentheses of a Function, the parameters that are plain text must be enclosed in single or double quotes.
Other parameters can be numbers or data references or functions which now don't need the = sign to differentiate them.
Yes that flip as you enter between the parentheses made little sense to me without the threefold classification and the "in some expressions" background. I could quite happily use the "Inside the parentheses" constructions on the outside as well. But (a) there might be some issue I've not thought of and (b) if I think of a typical simple line in a diagram text scheme like:

Code: Select all

C: %INDI.CENS[1+].DATE:YEAR% %INDI.CENS[1+].PLAC:SHORT%
then it would be that bit more complicated because I'd need to enter C: (for census, not C: drive!) between quotes, plus there'd be concatenation operators between the three elements - I think (no promises, I've not thought it through). Those of us less used to computer language constructions might be less pleased with that approach.

So yes, thanks for that Mike - all I have to do now is remember where I've filed this.
Adrian
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Re: Expression guidance please

Post by peterbel »

Now happily playing with expressions in diagrams :D
One comment, which might have been mentioned before, the entry box is too small for more than one expression.
I ended up working in Notepad and then cutting and pasting.
Tracing the Devon Bellamy family along with their partners.
User avatar
tatewise
Megastar
Posts: 28435
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Expression guidance please

Post by tatewise »

Peter, there is a longstanding 5-year-old Wish List Ref 545 Edit window for short Text fields that you can Vote for, and covers all short text fields, data fields, template fields, etc.

Yes, the workaround is to use something like Notepad which has the advantage that you can structure the expression over several lines to see that brackets are in balanced pairs and examine complex functions more clearly. Then remove the newline characters before pasting it into the template box.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
peterbel
Superstar
Posts: 348
Joined: 21 Nov 2014 20:24
Family Historian: V7
Location: Cornwall

Re: Expression guidance please

Post by peterbel »

Thanks Mike added my vote.
Tracing the Devon Bellamy family along with their partners.
Post Reply