Problem. One major drawback of the way computations are implemented in HotDocs is that they cannot be reused with different variables. Take, for example, Computation #0034: Full Name, which creates a full name from prefix, first, middle, last, and suffix. As a template may contain many names (Trustor, Petitioner, Registered Agent, etc.), this computation must be reproduced for each set of name variables. The result is component file bloat and wasted time creating and re-creating the same computation over and over (not to mention the nightmare of updating all of those computations once you realize they have a problem).
Solution: You can make your computations reusable by using generic, temporary variables in the computations. These variables are used to "pass" values to the computation. In other words, by SETing the generic variables before you call the computation, you can use the same computation throughout your template with any number of different variables. The examples below demonstrate how this works.
• • • • • • •
Example - Period-c Computation:
""
IF ".!?" CONTAINS LAST( Period-t, 1 )
// do nothing
ELSE
"."
END IF
This simple little computation checks a text variable, Period-t, to see if its last character can terminate a sentence ("!?."). If it can, all is well. Otherwise, the computation will return a period. A computation like this is useful in many places within a document. To make it reusable, I created the generic text variable Period-t (set its Advanced options to "Don't warn if unanswered," "Don't save in answer file," and "Ask only in dialog"). This variable belongs exclusively to the computation. When I want to test a variable to see if it needs a period, I simply SET Period-t TO the variable. Here is an example. Assume that this text is from my template:
The responsibilities of the Jester shall include «JesterDuties-t»«SET Period-t TO JesterDuties-t»«Period-c»
Taking it in order, the text of JesterDuties-t is inserted first, then this text is placed into the variable Period-t for analysis. Finally, the computation Period-c will determine whether a period needs to be placed.
• • • • • • •
Assume a computation called Fraction-c based on Computation #0116: (Even) Smarter Fraction Formatting. The main variable of Fraction-c (NumVar) should be changed to Fraction-n, a generic number variable (set the Advanced options to "Ask only in dialog," "Don't warn if unanswered," and "Don't save in answer file"). This makes the computation generic, allowing it to be accessed anywhere by simply setting Fraction-n to the value of the number you want formatted. Here is an example. Assume that this text is from my template:
The decimal value of the first number is «SomeNumber-n». We can convert this to a fraction: «SET Fraction-n TO SomeNumber-n»«Fraction-c». Another decimal number is «AnotherNumber-n». Its fraction is «SET Fraction-n TO AnotherNumber-n»«Fraction-c». The final decimal value is «LastNumber-n». Its fraction is «SET Fraction-n TO LastNumber-n»«Fraction-c».
Each of the number variables (SomeNumber-n, AnotherNumber-n, LastNumber-n) is placed in the computation's Fraction-n variable. The computation Fraction-c is then called, returning the appropriate fraction for the number. One computation has been able to service three different number variables.