Page 1 of 1

Need help with Expression: Distinguishing between WWI and WWII

Posted: 05 Dec 2022 21:41
by APerson
Hi All,

I’m trying to create an expression to generate an icon for military service in WWI and/or WWII; a separate icon should appear for each war. I’m running into a problem in that I currently have two expressions:
=IsTrue(ContainsText(%INDI._ATTR-MILITARY_SERVICE%,"ww1",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[2]%,"ww1",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[3]%,"ww1",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[4]%,"ww1",STD))
and
=IsTrue(ContainsText(%INDI._ATTR-MILITARY_SERVICE%,"wwii",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[2]%,"wwii",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[3]%,"wwii",STD) or ContainsText(%INDI._ATTR-MILITARY_SERVICE[4]%,"wwii",STD))
The problem is that each searches for the text “wwi” and because “wwi” is contained within “wwii,” two icons (for each war) appear when only wwii should appear. I’m sure that the solution to prevent this from happening would be to add an additional item to each expression so that only the appropriate icon appears based on the year. For example, the WWII icon should only appear if the military service occurred between 1940 and 1945. Unfortunately, I have been trying, unsuccessfully, to add the correct code to the expression.

Thanks for your help!

Re: Need help with Expression: Distinguishing between WWI and WWII

Posted: 05 Dec 2022 23:26
by tatewise
The general format for each instance of the fact would be:
(ContainsText(%INDI.FACT%,"wwi",STD) and ( Year(%INDI.FACT.DATE%) > 1913 ) and ( Year(%INDI.FACT.DATE%) < 1919 ))
and
(ContainsText(%INDI.FACT%,"wwii",STD) and ( Year(%INDI.FACT.DATE%) > 1938 ) and ( Year(%INDI.FACT.DATE%) < 1946 ))

You might think %INDI.FACT.DATE:YEAR% would be OK but does not cope with as many Date formats as the Year(...) function.

Substitute FACT with _ATTR-MILITARY_SERVICE and add indices [2], [3], etc, as necessary.

Re: Need help with Expression: Distinguishing between WWI and WWII

Posted: 06 Dec 2022 05:35
by APerson
Thanks, Mike, It worked!