# 70. Avoid ***Computation***

# Description

How to keep computations from returning ***Computation*** by providing a fall-back answer.

# Code

Text/MC Computations:

""

// Computation body here

IF RESULT = ""

// Fall-back value here

END IF

Number Computations:

0

// Computation body here

IF RESULT = 0

// Fall-back value here

END IF

Date Computations:

DATE OF( 1, 1, 1582 )

// Computation body here

IF RESULT = DATE OF( 1, 1, 1582 )

// Fall-back value here

END IF

# Explanation

When a computation returns ***Computation***, it means that there was an unanswered variable, usually in an IF ... END IF block. By way of explanation, when HotDocs tests IF Variable = Value, there will be one of three results: TRUE, FALSE, or NULL. A NULL value occurs where Variable is ***Unanswered***, meaning that the expression is neither true nor false. Because it is neither true nor false, HotDocs simply skips the whole structure down to the END IF.

The way to avoid a ***Computation*** result is to start the computation with a default value. The typical defaults are "" (an empty string) for text computations, 0 for number computations (or some arbitrary value that your computation could not produce, such as -7878), DATE OF( 1, 1, 1582 ) or 01 JAN 1582 for date computations, and either TRUE or FALSE for true/false computations, as appropriate. This assures that the computation will have some value. You can then provide a test at the end of the computation to see if the default value remains unchanged (meaning that the body of the computation failed to produce a different value - probably because of an error). If so, you can try to make up for the error with a fall-back test.

The following example illustrates this principle. The computation sets the value of the text variable Supervisor-t according to who the StaffMember-t is. If StaffMember-t is unanswered or is a name not contemplated in the computation, the fall-back will take effect. (Note that simply using an ELSE will not produce the same result, since the ELSE section will never be evaluated if StaffMember-t is unanswered).