Search

What the Quote?

"I'm better than you, snob."

Laura Tripcony

"I'm tired. And the music is absurd."

Laura Tripcony

"I knew that was what they were doing. I could feel it in my puke glands."

Laura Tripcony

« Creating documents in Domino without using a form or an agent | Main| Probably useless - LotusScript toAcronym() »

Parsing formulas on the fly via @Eval and @While

Category show-n-tell thursday
Here's the scenario: configuration documents are used to define content (i.e. selectable values in a drop-down), but that content must be a mixture of statically and dynamically defined information, and how the dynamically defined content is determined needs to be adaptable over time. If you're at R6 or above, this is easy: place any formula that should be evaluated at run-time within wiki-style markup in the configuration data, then parse it using @While and @Eval.

strContent := (reference to configuration data, such as a field on the current document or a DbLookup);
@While( @Contains(strContent;"[formula]");
strLeftOfMarkup := @Left(strContent;"[formula]");
strRightOfMarkup := @Right(strContent;"[/formula]");
strRunTimeFormula := @Right(@Left(strContent;"[/formula]");"[formula]");
strContent := strLeftOfMarkup + @Eval(strRunTimeFormula) + strRightOfMarkup
);
strContent

This could be used, for example, to dynamically specify dynamic information at the top of a web page:

Welcome to the [formula]@DbTitle[/formula] website. You are currently logged in as [formula]@Name([CN];@UserName)[/formula].

Then if you later decide to change what information is displayed or how it is determined (i.e. evaluate a querystring), you can do so simply by updating the configuration data, instead of having to update the application's code.


Comments

Gravatar Image1 - I do something similar for my workflow notification code and my export to excel code. I use place holders that get replaced by data from the document being manipulated. The cool part about doing things like this is that it's very easy to write generic snippets of code that can be used in multiple databases.

Sean---