# Need help with a recursive function

This topic is 2224 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

Hey Guys I've wrote this function but just can't get it to work. The plan is to inject some content (template) and for it to iterate through each word looking for a formula, i.e. {{If([[CarMake]] = "Volvo"; "Volvo" ; "Other" )}} and evaluate it. I think the calculation I have is working fine, but I can't quite manage to work out how to loop through each word in the content. I've tried to reverse engineer Ray Cologens Mail Merge formula as that custom function kind of did what I needed, but I didn't need all of it.

MergeText(Template)

Let([

start_pos = Position(Template; "{{"; 1; 1);
end_pos = Position(Template; "}}"; start_pos; 1);
formula = Middle(Template; start_pos + 2; end_pos - start_pos - 2);

formula_VARS = Substitute(formula ;

["[[CarMake]]";"\$CarMake"];

["[[CarModel]]";"\$CarModel"];

["[[CarType]]";"\$CarType"]
);

original_formula = "{{" & formula & "}}";

evaluated_formula =  If(EvaluationError(Evaluate(formula_VARS)); "Invalid Formula"; Evaluate(formula_VARS))
]
;

Case(
Right(Template ; 1 ) <> ¶ ; MergeText(Template & ¶) ;

start_pos > 0 and end_pos > start_pos ; MergeText(Substitute (Template ; original_formula ; evaluated_formula ) ) ;

Template

)

)

##### Share on other sites

You did not explain what the function is supposed to do. Looking at it superficially, it would seem a simple Substitute() could do the job?

##### Share on other sites

This topic is 2224 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account