76. "Same As Above" - Carry answers forward
Description
Copies answers from the previous repeated dialog window into the current window.
Code
(Dialog Script for "RepeatedDialog")
SET Temp-n TO COUNTER - 1
("Same as Above" Computation)
""
SET FirstName TO FirstName[ Temp-n ]
SET MiddleName TO MiddleName[ Temp-n ]
SET LastName TO LastName[ Temp-n ]
Variation on "Same as Above" Computation:
""
IF ANSWERED( FirstName ) = FALSE
SET FirstName TO FirstName[ Temp-n ]
END IF
IF ANSWERED( MiddleName ) = FALSE
SET MiddleName TO MiddleName[ Temp-n ]
END IF
IF ANSWERED( LastName ) = FALSE
SET LastName TO LastName[ Temp-n ]
END IF
Explanation
This computation copies answers from the previous repeated dialog window forward into the current window. The computation requires the following:
A repeated dialog, here called "RepeatedDialog"
A dialog script in RepeatedDialog to note the current repeat level (requires HotDocs Pro)
A custom button on RepeatedDialog to trigger the "Same as Above" computation
A computation variable to carry forward the answers
The computation is triggered by a custom button on the dialog window. To create the button, type the following in the "Additional Text" window of the dialog, then drag it into place on the list of variables:
@COMPUTE:ComputationVariable:Same As Above
Substitute "ComputationVariable" with the name you will give to the computation. Next give RepeatedDialog the following script:
SET Temp-n TO COUNTER - 1
This line determines the current level of the repeated dialog with COUNTER, subtracts one to obtain the previous level, and sets this value in the temporary number variable Temp-n. We will refer to this value within the computation. Important: Do not include Temp-n as one of the dialog's variables! This will prevent the dialog from terminating unless you use the "Finish" button. Also, set Temp-n's options to "Ask only in dialog," "Don't warn if unanswered," and "Don't save in answer file."
Next we create the computation itself. It simply SETs any answer in the current window to the corresponding answer in the previous window. In our example, we SET the text variables FirstName, MiddleName, and LastName. You will want to change the variable names to those you use in your dialog. You may SET as many or as few variables as you wish.
The previous answers are referenced by indicating their repeat level in square brackets following the variable name. For example, FirstName[1] returns the answer to FirstName in the first dialog window, while FirstName[5] returns the answer to FirstName in the fifth dialog window. And FirstName[ Temp-n ] returns the answer to FirstName in the Temp-n dialog window. Since we SET Temp-n to the most recent repeat level in the dialog script, we know that it will always refer to the previous dialog window.
The variation will only SET an answer if the field does not currently have an answer.
CAVEAT #1: Do not try to SET Temp-n outside of the dialog script. COUNTER is always 1 outside of the dialog script.
CAVEAT #2: Using COUNT( RepeatedDialog ) - 1 in the computation instead of using SET Temp-n TO COUNTER - 1 in the dialog script will work, but only the first time that the dialog is filled in, or when adding additional answers to the dialog. It will not work for changing answers already entered into the repeated dialog. Rather, clicking the "Same as Above" button will always insert the answer from the second-to-last dialog window rather than the previous window.
CAVEAT #3: For some reason, COUNT and COUNTER can only be called once per use of the "Same as Above" computation. Multiple calls produce errors ("You cannot use COUNT in a repeated dialog"), and only one answer is brought forward. This is why we SET the COUNTER to a number variable.
FINAL TIP: This computation has been hashed and rehashed over and over. The scripts provided seem to be the only way this will work. Save yourself some grief: don't try to get creative.