User Defined Macros
Posted: 02 Oct 2011 16:14
A recent FH Mailing List dialogue suggested that User Defined Macros for Expressions would make the exchange of complex Data References and Functions more reliable and convenient. This would allow 'experts' to create sophisticated expressions, or partial expressions, that others could use, without the risk of introducing basic syntax errors.
Although User Defined Macros look like Functions, they actually use simple text string substitution logic.
So for example =SpouseName() could be defined as %INDI.~SPOU[$1]>NAME[1]% where $1 represents the 1st macro parameter.
Thus:
=SpouseName(1) would become %INDI.~SPOU[1]>NAME[1]% the 1st spouse.
=SpouseName(2) would become %INDI.~SPOU[2]>NAME[1]% the 2nd spouse.
=SpouseName(3) would become %INDI.~SPOU[3]>NAME[1]% the 3rd spouse.
(If an actual $ character were needed then it would be represented by $$.)
To allow a list of spouse names with space separators it could be defined as %INDI.~SPOU[$1]>NAME[1]% . ' '
With the =CombineText() function and custom separators it would be =CombineText( $2, %INDI.~SPOU[$1]>NAME[1]% )
So for example =SpouseName(3,' & ') would become =CombineText( ' & ', %INDI.~SPOU[3]>NAME[1]% )
Alternatively, a complete spouse name list Macro called =AllSpouseNames(&) could be defined as
=CombineText(,%INDI.~SPOU[1]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[2]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[3]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[4]>NAME[1]%))))
ID:5495
Although User Defined Macros look like Functions, they actually use simple text string substitution logic.
So for example =SpouseName() could be defined as %INDI.~SPOU[$1]>NAME[1]% where $1 represents the 1st macro parameter.
Thus:
=SpouseName(1) would become %INDI.~SPOU[1]>NAME[1]% the 1st spouse.
=SpouseName(2) would become %INDI.~SPOU[2]>NAME[1]% the 2nd spouse.
=SpouseName(3) would become %INDI.~SPOU[3]>NAME[1]% the 3rd spouse.
(If an actual $ character were needed then it would be represented by $$.)
To allow a list of spouse names with space separators it could be defined as %INDI.~SPOU[$1]>NAME[1]% . ' '
With the =CombineText() function and custom separators it would be =CombineText( $2, %INDI.~SPOU[$1]>NAME[1]% )
So for example =SpouseName(3,' & ') would become =CombineText( ' & ', %INDI.~SPOU[3]>NAME[1]% )
Alternatively, a complete spouse name list Macro called =AllSpouseNames(&) could be defined as
=CombineText(,%INDI.~SPOU[1]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[2]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[3]>NAME[1]%,CombineText(' $1 ',%INDI.~SPOU[4]>NAME[1]%))))
ID:5495