Split an Answer at a Specified Length

From HotDocs Wiki

Jump to: navigation, search

Sometimes, you may want to split an answer, placing the first part of the answer in one place on your template and the other part in a different place. This is most common in form templates where space is limited. For example, if a form template provides a space to describe a client's medical history, it is likely that the history could require more than the allotted space. Rather than sending the entire answer to an addendum, you can write a computation that places the first part of the answer in the allotted space, then send the rest to the addendum.

The following computation uses 100 as the arbitrary maximum number of characters allowed on the template. If the answer is longer than 100 characters, the computation searches for the last space in the first 100 characters. By finding this space, the computation can split the answer more intelligently, rather than simply splitting it at the 100th character even if that means splitting in the middle of a word.

After the computation determines the place to split the answer, it returns the first part of the answer as its result. The second part of the answer is then stored in a temporary Text variable, which is used to create the addendum. If there are fewer than 100 characters to begin with, the temporary Text variable is empty, so nothing is sent to the addendum.

NOTE:

When adapting this computation for use in your own template, you must determine the number of characters that will fit in the space on your template. In determining this number, keep in mind that for most fonts, the width of each character is different and your number will be only a rough estimate. Therefore, you should base your estimate on the lowest number of characters possible, rather than the highest number.


CAUTION: This computation uses the WHILE instruction, which works only in HotDocs 6.2 and higher.

Example

"" 
IF LENGTH( Text Var 1 ) > 100 
  SET Num Var TO 100 
  WHILE MID( Text Var 1, Num Var, 1 ) != " " 
    DECREMENT Num Var 
  END WHILE  
  FIRST( Text Var 1, Num Var - 1 ) 
  SET Text Var 2 TO LAST( Text Var 1, LENGTH( Text Var 1 ) - Num Var ) 
ELSE  
 Text Var 1 
  SET Text Var 2 TO "" 
END IF

Text Var 1 Any Text variable.
Text Var 2 A temporary Text variable that contains all of the text that does not fit in the first space. (See Create a Temporary Variable.)
Num Var A temporary Number variable used in the WHILE loop