The HotDocs Computation Archive

0111 - Multiple Choice Variable as a Text Value


Description:

How to use a multiple choice variable as a text value.

 

• Code •

"Select One Only" MC Variable:

SET TextVar TO MCVar

"The value of the multiple choice is: " + MCVar

FIRST( MCVar , 2 )

MCVar CONTAINS "Ralph Malph"
 
 
"Select All That Apply" MC Variable:

SET TextVar TO "«MCVar»"
SET TextVar TO "«MCVar::a, b and c»"

"The value of the multiple choice is: «MCVar»"
"The value of the multiple choice is: «MCVar::a, b and c»"

FIRST( "«MCVar»" , 2 )

"«MCVar»" CONTAINS "Ralph Malph"

but ...

MCVAR = "Ralph Malph"

• Explanation •

The Problem. When a multiple choice variable is set to "Select All That Apply," something unexpected happens: It no longer returns a text value. Notice in the first set of examples above that a multiple choice variable set to "Select One Only" always returns a text value. It can be used just like a text variable. But when the multiple choice variable is changed to "Select All That Apply," the variable no longer returns a text value. Trying to use it as a text variable will produce an error.

The Solution. You can coerce a text value from a multiple choice variable in the same way that you coerce text values from date, number, and true/false variables. Namely, place the variable between chevrons within a quoted string. This is demonstrated in the second set of examples above. When you do this, it is advisable to provide a list formatting example as shown. If you fail to provide a formatting example the selections will be returned in a columnar list (a carriage return between each answer). For a further description of how to include formatting examples and other extended information for a variable, see Computation #0093: Variable Arguments.