Epi Info™ User Guide

Command Reference


Check Commands: Assign


Description
This command assigns data to a field or variable.  The data assigned can be a literal value or the result of an arithmetic or string expression.

Syntax
ASSIGN <variable> = <expression>
ASSIGN <variable> = <defined DLLOBJECT>!<script function>({<parameters>})

  • The <variable> represents a field in a database or a defined variable created in Check Code program.
  • The <expression> represents any valid arithmetic or string expression.
  • The <defined DLLOBJECT> represents any variable defined as a dynamic linked library (DLL) object or Windows Script Component (WSC).
  • The <script function> represents the name of a class or method inside the DLL or WSC that returns the desired value to be assigned.
  • The <parameters> represent one or more optional function parameters to be passed into the DLL or WSC (do not include the {} or <> symbols in the code; parenthesis are required).

Comments
This command assigns a literal value or the value of an expression to a field or variable.  The target of the assignment may be a field in the form, or column in a data table, a user-defined variable created with the DEFINE command, or a system variable.

Examples
Example 1:  The patient’s age is calculated using the date of birth and the date the survey was last updated. The example assumes a form exists with the following fields: BirthDate (Date), SurveyDate (Date), and Age (Number). The code below would appear in the AFTER section of the second date field to be filled in by the user.  If BirthDate is not blank and SurveyDate is not blank, then assign the number of years between BirthDate and SurveyDate to the field named Age.

IF NOT BirthDate = (.) AND NOT SurveyDate = (.) THEN 
   ASSIGN Age = YEARS(BirthDate, SurveyDate)
END-IF

Example 2:  If the value ‘Age’ is less than 18, then assign the checkbox field ‘Minor’ to true (checked).   The example assumes a form exists that has the following fields: Minor (Checkbox) and Age (Number). The code below would appear in the AFTER section of the Age field.

IF Age < 18 THEN
   ASSIGN Minor = (+)
END-IF

Example 3:  Assign the field named BMI the value of a mathematical expression that calculates body mass index.  The example assumes a form exists with the following fields: BMI (Numeric), Weight (Numeric), and Height (Number). The code below would appear in the AFTER section of the last field to be entered. Note that this formula uses Weight and Height in units of pounds and inches, respectively.

ASSIGN BMI = (Weight / (Height * Height)) * 703

Example 4: Generate a patient ID using the patient’s last name, gender, and middle initial.  The formatting includes a hyphen between last name and sex, and the middle initial is enclosed in parentheses.  The example assumes a form exists with the following fields: ID (Text), LastName (Text), Sex (Text), and MI (Text). The code below would appear in the AFTER section of the last field to be entered.

ASSIGN ID = LastName & " - " & Sex  & " (" & MI & ")"
Page last reviewed: September 16, 2022, 12:00 pm