Epi Info Check Code User Guide
Epi Info Check Code User Guide
CHECK CODE
i
Preface
Epi Info™ is a public domain suite of interoperable software tools designed for the
global community of public health practitioners and researchers. Perform data
analysis with epidemiologic statistics, maps, and graphs. Build data entry forms,
construct a database, and customize statistics applications. Physicians,
Epidemiologists, and public health officials without a technical background can
easily work with critical data using Epi Info™ tools.
Use this guide alone or as a supplement to other Epi Info™ guides. On the next
page, view the complete collection of helpful guides available for Epi Info™ tools.
The diagram shows how this guide highlighted with the bookmark icon fits into
the big picture of the Epi Info™ suite. Additional guides may offer prerequisite
information for the tool you’re working with. For example, if you’re working with
Epi Info™ Check Code (EICC), then you are using code to customize fields in Form
Designer. Therefore, you may need to begin by consulting the Epi Info™ Guide to
Form Designer and Epi Info™ Guide as indicated by the prerequisite
documentation icon ( ). Additionally, you may find helpful other guides that are
indicated by the optional documentation icon ( ).
ii
iii
This page has been intentionally left blank.
TABLE OF CONTENTS
INTRODUCTION ........................................................................................................................................... 1
Concatenate Fields............................................................................................................................. 29
CALL ................................................................................................................................................... 37
CLEAR ................................................................................................................................................ 39
DEFINE .............................................................................................................................................. 40
DISABLE ............................................................................................................................................ 41
HIDE/UNHIDE .................................................................................................................................... 45
ENABLE/DISABLE ............................................................................................................................. 48
EXECUTE ........................................................................................................................................... 49
GEOCODE ......................................................................................................................................... 51
HELP .................................................................................................................................................. 55
NEWRECORD.................................................................................................................................... 56
QUIT ................................................................................................................................................... 56
The Check Code tool allows users to customize the data entry process. Use Check
Code to check for errors during data entry, conduct automatic calculations in survey
fields, and to skip parts of the survey if they meet certain conditions. Protect
collected data against many common errors by creating rules for data entry. Check
Code operations run each time a participant enters data or when triggered by
Click the Check Code button to navigate to the Check Code Program Editor in the
Form Designer tool bar after opening your Epi Info™ 7 project.
You can also select Tools > Check Code Editor from the Form Designer navigation
menu.
2
Epi Info – Guide to Web Survey
• Program Editor
• Messages
Sections:
1. Choose Field Block for Action tree — allows you to select form fields and
2. Add Command to Field Block window — displays all current Check Code
created from Choose Field Block for Action or Add Command to Field
3
Epi Info – Guide to Web Survey
Block window. Users can also type directly and save the code into the
Program Editor.
There are several options on the toolbar at the top left, allowing you to save, edit,
Close Check Code Program Editor and return to your form by clicking on the X
button at the top right of your screen. You can also click on the Close button or
Check Code commands must be within a field-name block. Command blocks begins
with a field, page or form name and end with the word End. Commands in a block,
activate before or after entering data into a field. For some field types, blocks
activate when clicking on the control (i.e.: checkboxes and command buttons).
Usually, commands activate after the user presses the Enter key, or when the
cursor has left the field. Change command activation by placing commands in
Field <Variablename>
After
—Check Code syntax inserted here—
End-After
End-Field
4
Epi Info – Guide to Web Survey
soon as the cursor leaves the field. Before and Click are the other two
events supported. A Click event executes when the user clicks on the field
and is only supported for Legal Values, Comment Legal, Checkboxes, and
Command buttons. The Before event executes as soon as the cursor moves
Code. Code is placed between the After and End-After sections and code
field.
In the example below, we have incorporated an After event for a field called DOB.
The Check Code block executes a value assignment to the field Age, using the
YEARS function. The YEARS function calculates the difference between two date
Field DOB
After
ASSIGN AGE = YEARS(DOB, SYSTEMDATE)
End-After
End-Field
5
Epi Info – Guide to Web Survey
• Before or after you make an entry in the field or when you click on
button).
• When a command moves the cursor out of the field (e.g., GOTO).
5. User interaction with the dialog boxes triggers Check commands. Syntax is
displayed in the Check Code Editor. You can edit and save text in the
Program Editor.
6. Insert Before and After commands into forms, fields, pages, or records.
Steps:
1. Select and expand the form, page, record, or field that will receive the
6
Epi Info – Guide to Web Survey
2. Select command execution. (i.e.: before or after data entry into the form,
7
Epi Info – Guide to Web Survey
After event
3. Double-click on the after event or click on the after event and then click the
Add Block button to insert the block. The Check Code block appears in the
8
Epi Info – Guide to Web Survey
Insert commands within a new Check Code block using the Add Command to
Create skip patterns by changing tab order and setting new cursor sequences in
forms. Try creating Check Code using the GOTO command. Create skip patterns
added Check Code moves the cursor to the Ethnicity field after participants enter
data into the DOB field and skipping the AGE field.
Steps:
3. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
4. Expand the node for Page 1, from the Choose Field Block for Action
9
Epi Info – Guide to Web Survey
7. A block of code for the DOB field displays in the Check Code editor.
Click GOTO from the Add Command To Field Block list box. The GOTO dialog
box opens.
Select the EthnicityGroup field for cursor placement, after an entry in the DOB
field. The code will run after the cursor leaves the field.
10
Epi Info – Guide to Web Survey
Test the skip pattern by opening the form in the Enter Data tool. Move to the Data
of Birth field and press the tab key to execute the GOTO command.
11
Epi Info – Guide to Web Survey
the form. This example creates code for a participant who answers “No” for the
Hospitalized field, then the cursor jumps to the field: Was the patient treated
3. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
4. From the Choose Field Block for Action section, expand the node for the
8. Check Code Editor displays a block of code for the Hospitalized field.
12
Epi Info – Guide to Web Survey
1. Click If from the Add Command to Field Block list box. The If dialog box
opens.
2. Select the field from the Available Variables drop-down list to contain the
action. For this example, select Hospitalized. The selected variable appears
4. Click No from the operators list. The If Condition field will read Hospitalized
= (-).
5. Click the code snippet button in the Then section. A list of commands
appears.
6. From the command list, select GOTO. The GOTO dialog box opens.
7. Select the field for cursor placement if the participant answers, No, from the
13
Epi Info – Guide to Web Survey
Click OK. The Check Code editor displays the code. The example code appears:
9. Click the Verify Check Code button from the Check Code Editor.
14
Epi Info – Guide to Web Survey
command. For example, Check Code calculates the age of a participant based on
date of birth and the form completion date (calibrated to the system date).
This example uses the Date Of Birth (DOB) and Age fields. (i.e.: from the
1. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
2. Expand the node from the Choose Field Block for Action section, where
3. Expand the node for the date of birth field called DOB.
5. The Check Code Editor displays a block of code for the DOB field.
6. Click Assign, from the Add Command to Field Block list box. The Assign
8. Select the Age field from the Assign Variable drop-down list.
15
Epi Info – Guide to Web Survey
12. Double click on the <start_date> parameter. This highlights the command
section.
command section.
16
Epi Info – Guide to Web Survey
7. Click the Verify Check Code button in the Check Code Editor.
17
Epi Info – Guide to Web Survey
When entering a date of birth into the form, the Age field populates.
Interact with data entry personnel from within the program, using the DIALOG
command. Dialogs display information, requests and receives input, and generates
helpful lists, assisting survey respondents. In the following example, the DIALOG
command creates a reminder that respondents must complete all fields on page two.
[Link].
18
Epi Info – Guide to Web Survey
2. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
3. Select page 2 from the Choose Field Block for Action list box. The action
Before action
19
Epi Info – Guide to Web Survey
7. From the Add Command to Field Block list box, select Dialog. The
10. In the Prompt field, type: “All fields on page two must be completed.”
20
Epi Info – Guide to Web Survey
2. Click the Verify Check Code button from the Check Code Editor.
values and notifies the user. You can edit the matching record or continue entering
duplicate records. View the example using AUTOSEARCH on the CaseID field.
[Link].
2. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
3. From the Choose Field Block for Action section, expand the node for page 1
21
Epi Info – Guide to Web Survey
6. Check Code Editor displays a block of code for the CaseID field.
22
Epi Info – Guide to Web Survey
From the Add Command to Field Block list box, click AUTOSEARCH. The
Select the search variable(s) during data entry. In this example, select CaseID.
Click OK. The code appears in the Check Code Editor window.
23
Epi Info – Guide to Web Survey
The AUTOSEARCH dialog box opens with all the matching records when a
duplicate record is entered from the Enter Data tool. View and clear the duplicate
record by double-clicking the arrow next to the record. Otherwise, click Cancel to
remain on the current record and accept the duplicate value. To display other
matching record variables, add the variable names after the DISPLAYLIST
parameter (i.e., Last Name, First Name and Date of Birth as shown below).
Field CaseID
After
//add code here
24
Epi Info – Guide to Web Survey
In the Check Code above, AUTOSEARCH will find matching records on the field
CaseID. Detected matching records display the following fields on the grid: CaseID
After building a relational database using Epi Info™ 7, best practices suggest
transferring field values in the parent form (i.e., core demographics) to the child
form (i.e., visits information). Accomplishing this requires existing Check Code from
25
Epi Info – Guide to Web Survey
field values in both parent and child forms. (i.e., Visible Case ID Number or
The following instructions assume the parent and child forms already exist. Let’s
name the parent form Surveillance while the child form is called Hepatitis. A
create it. Afterward, use Check Code in Hepatitis (i.e., LastName in parent form
is transferred to LastName in child form). Let’s call the parent form field name:
Open your project from Form Designer and click on the child form from the
2. Create a new field. The new field must be the same field type as the field
being copied from the parent form. For this example, use PatientId.
4. Click OK. The new field appears in the form. A value from the parent form
will be assigned and displayed during data entry on the child form.
5. Click Check Code or select Tools > Check Code Editor. The Check Code
Editor opens.
6. From the Choose Field Block for Action list box, select the page
corresponding to the location of the PatientId field. Let’s assume this field is
on page 1. For the page, select the <before> from the before or after section.
26
Epi Info – Guide to Web Survey
1. From the Add Command to Field Block list box, click Assign. The Assign
2. From the Available Variables drop-down list, select the new variable,
PatientId.
3. In the = Expression area, type the field name from the parent form. In this
case, use PatientId. Add a prefix followed by a period for the field name, in
27
Epi Info – Guide to Web Survey
4. Click OK.
Check Code Editor displays the code. If parent and child forms have the same field
name, distinguish the field name during the copy operation. Always prefix the field
Steps:
• Determine if the child field and the parent field have the same
name
• Add a prefix to the field name.
• Add a period in Assign expression.
Hepatitis is the name of the child form; Surveillance is the name of the parent
form. If parent and child forms do not have the same field name, only use the field
name in the syntax. Follow the syntax example in the image below.
28
Epi Info – Guide to Web Survey
Click the Validate Check Code and correct any issues. Then click Save.
Concatenate Fields
Check Code syntax will work for new records with concatenating fields. Check Code
syntax won’t work retroactively. Your code won’t execute on old records with
This example illustrates how to join data from two fields and assign it into a third
field using the ‘&’ operator. The example shows how PatientFullName is assigned
3. Select LastName from the Choose Field Block for Action list box.
29
Epi Info – Guide to Web Survey
6. Go to the Add Command to Field Block list box, click Assign. The Assign
7. From the Assign Variable drop-down list, select the field for the
concatenated value.
8. Create the = expression using the & operator. In this example, Assign
30
Epi Info – Guide to Web Survey
10. Click the Validate Check Code button and correct any issues and click
Save.
For example, using the Enter Data tool, add Carl for FirstName and Gao for
between CarlGao by changing the ASSIGN statement. Add a blank space in quotes
This example illustrates how to join segments of two variables to create a unique
text ID. In this example, create a Patient ID made up of segments of the patient's
last and first name. Use the ampersand (&) operator and join the two segments
together.
31
Epi Info – Guide to Web Survey
Steps:
1. Click Check Code from the Form Designer. The Check Code Editor opens.
2. Select FirstName, from the Choose Field Block for Action list box.
5. Click Assign, from Add Command to Field Block list box The Assign
6. Select the field to contain the concatenated value from the Assign Variable
variable
In this example, the PatientID variable contains a combination of the first position
and four characters of the last name plus the first position and three characters of
32
Epi Info – Guide to Web Survey
9. Click Validate Check Code button and correct any issues, and then click
Save.
Add Check Code to option box fields. Add Code to any line/choice in the option
boxes. Use the Check Code Editor and create complex Check Code for option box
fields.
The Check Code GOTO command works in the following scenario. If the answer to
Test Options is Choice 1, the cursor will jump to Question 2. If the answer to
Test Options is Choice 2 or Choice 3, the cursor will jump to Question 1. Check
the tab order before creating the Check Code to ensure accuracy.
3. Select TestOptions, From the Choose Field Block for Action list box.
6. Click If from the Add Command to Field Block list. The IF dialog box
opens.
9. Click the Code Snippet button in the Then section. A list of commands
appears.
10. Select GOTO, from the command list. The GOTO dialog box opens.
35
Epi Info – Guide to Web Survey
If dialog box
13. Click Validate Check Code and correct any issues, then click Save.
Steps:
Note: Confirm all deletions before making them. Deletions are permanent.
36
Epi Info – Guide to Web Survey
CALL
This command redirects to another command block in Check Code and returns after
execution. Calls and subroutines work together. Subroutines act as a Check Code
common unit, usually dependent on two variables. The benefit of using subroutines
example of a subroutine:
uses the After event. Place the After event after the AdmissionDate and
location. The CALL command executes a block of Check Code in multiple fields.
37
Epi Info – Guide to Web Survey
Create a Subroutine
Steps:
3. Expand the subroutine item from the Choose Field Block for Action list
4. Double click on the Add new item. A New Subroutine window opens.
38
Epi Info – Guide to Web Survey
A new block of code for the subroutine called MySubroutine1 displays in the
Check Code Editor. Determine the Check Code commands for the subroutine. Verify
your code and save your work. The user will need to place the CALL command with
the name of the subroutine in each desired field in order to execute the Check Code
CLEAR
If a field entry is incorrect, CLEAR sets the field with a null value as if it were
blank. It’s useful when the entry in the field contains an error to use the CLEAR
command with the GOTO command. Working in tandem, the commands return the
cursor back into the field so the participant may try again. Below, CLEAR removes
data from the DateofInterview field after flagging the user with a message, “Date
of interview is greater than today’s date.” The entry is cleared, and the user can try
again.
39
Epi Info – Guide to Web Survey
DEFINE
This command creates a new variable. Check Code saves all user-defined variables
• <scope> is optional and is the level of visibility and availability of the new
variable. This parameter must be a reserved word: STANDARD, GLOBAL, or
PERMANENT. If omitted, the code assigns STANDARD as the parameter
and omits, a <field type indicator>.
• <field type indicator> is the data type of the new variable and must be
one of the following reserved words: NUMERIC, TEXTINPUT, YN,
DATEFORMAT, TIMEFORMAT and DLLOBJECT.
40
Epi Info – Guide to Web Survey
Warning: If omitted, the data type infers the variable type of the first assigned
value. Thereafter, the variable type is unchangeable, and results in an
error.
• STANDARD variables keep their values only within the current record.
Values reset when loading new records. Standard variables work like
• GLOBAL variables keep their values across related forms, even after
opening a new form. Global variables persist for the duration of program
execution. Global variables end when closing the Enter Data tool.
Note: Find Permanent variables in the [Link] file located in the \Epi
Info 7 > Configuration directory.
DISABLE
If a field isn’t required for data collection, use the DISABLE Check Code command.
Use If, Then, and Else conditionals Check Code commands to DISABLE a field. In
this example, the field DoctorVisitDate will be disabled if the response to the
DoctorVisit is No.
41
Epi Info – Guide to Web Survey
3. Select the DoctorVisit from the Choose Field Block for Action list box.
42
Epi Info – Guide to Web Survey
1. Click IF from the Add Command to Field Block list box. The IF dialog box
opens.
2. From the Available Variables drop-down list, select the field to contain the
action. For this example, select DoctorVisit. The selected variable appears
4. From the operators list, click No. If Condition field reads DoctorVisit=(-).
5. Click the Code Snippet button in the Then section. A list of available
commands appears.
6. From the command list, select DISABLE. The DISABLE dialog box opens.
9. Click the Code Snippet button in under the Then section. A list of available
commands appears.
10. Select Enable From the command list. The Enable dialog box opens.
43
Epi Info – Guide to Web Survey
11. Select the field to enable based on a “Yes” answer from the list of variables.
12. Click OK to in the Enable dialog box to return to the If dialog box.
13. Click OK. The code appears in the Check Code Editor. View the code in the
image below.
44
Epi Info – Guide to Web Survey
Click:
• Save.
Note: Test DISABLE by opening the form in the Enter Data tool. Entering “No” for
the DoctorVisit field will disable the DoctorVisitDate field.
HIDE/UNHIDE
Form designers can hide a field by using the HIDE command. HIDE works for
removing fields that are non-applicable. View the following example. HIDE removes
the Pregnant option box. The response for sex triggers the HIDE command,
removing the Pregnant option box, following a respondent answer to their sex.
2. Select Sex from the Choose Field Block for Action list box.
4. Click the Add Block button. The code runs after data entry.
45
Epi Info – Guide to Web Survey
6. Click If, from the Add Command to Field Block list box. The If dialog box
opens.
7. Select the field from the Available Variables drop-down list. Select Sex for
9. Type Sex = “Male” from the If Condition field. Remember that Sex is a
10. Click the Code Snippet button under the Then section. A list of commands
appears.
11. Select HIDE, From the command list. The HIDE dialog box opens.
46
Epi Info – Guide to Web Survey
13. Click the Code Snippet button in the Else section. A list of commands appears.
14. Select UNHIDE from the command list, The UNHIDE dialog box opens.
15. Select the field to unhide, if the participant answers, “yes.” Select Pregnant.
16. Click OK in the Unhide dialog box, to return to the If dialog box.
17. Click OK, and then again, OK. Check Code Editor displays the code.
47
Epi Info – Guide to Web Survey
Note: The Unhide command shows any hidden fields. You can select this command
in the Add Command to Field Block section of Check Code Editor. Use a
CLEAR command with the HIDE command to set to null, any information
previously entered in the Pregnant field.
ENABLE/DISABLE
These commands can work in conjunction. The DISABLE command disallows data
entry into a field while the ENABLE command allows data entry into a previously
disabled field.
48
Epi Info – Guide to Web Survey
EXECUTE
designated within the Windows registry. (i.e., A file with extension listed in a
Windows registry). Using the EXECUTE command, Windows launches the default
program(s) listed in its registry. The EXECUTE command accepts a series of paths,
EXECUTE c:\Users\MyPC\[Link];d:\[Link]
EXECUTE command in any command block. You can use it with a command
button. Execute Check Code syntax when you click on the command button.
49
Epi Info – Guide to Web Survey
• The <filename> represents the path and program name for .exe files and
• When using the WAITFOREXIT command (modal), the command runs and
Enter pauses until the command has finished. Then, Enter runs subsequent
variables before the command runs, and reloads them again, afterward.
In the example below, the CDC website page opens when the users click on a
command button called OpenCDCWebsite. A PDF file opens when the users click
50
Epi Info – Guide to Web Survey
GEOCODE
The Geocode command uses data entered in a text field which corresponds to an
into the form. When using Desktop, this command will require an Internet
connection.
3. Select GetCoordinates from the Choose Field Block for Action list box.
4. Select Click.
5. Click the Add Block button. This creates code to run after the GetCoordinates
51
Epi Info – Guide to Web Survey
2. Select Geocode from the Add Command to Field Block list box. The
52
Epi Info – Guide to Web Survey
1. Click OK.
2. Click OK. Check Code Editor displays the code. Click Save, then click Close.
53
Epi Info – Guide to Web Survey
The Geocode Results dialog box contains the address, Latitude and Longitude
coordinates. Also, you can view the confidence level of geocode service coordinates.
Click Accept in the Geocode Results dialog box. The geocode service coordinates
54
Epi Info – Guide to Web Survey
HELP
Displays a pop-up help window containing a message. The help window works with
large files by allowing users to move from one highlighted block of text to another. It
HIGHLIGHT/UNHIGHLIGHT
yellow. Highlighting is useful when errors are detected. Fields can be highlighted
and unhighlighted. View the example below. The highlighted field Emergency is
triggered by a response to the field: Vaccinated = “No”. So, the field: “Did you
visit the emergency room?” is highlighted, skipping over the rest of the
vaccination questions.
55
Epi Info – Guide to Web Survey
HIGHLIGHT/UNHIGHLIGHT command
NEWRECORD
The NewRecord command saves the current records data and opens a new record
for data entry.
QUIT
This command saves the current record and closes the Enter application.
56
Epi Info – Guide to Web Survey
REQUIRED prevent records from being saved until the fields are filled in.
Entering data allows participants to continue. In the example below, the field:
REQUIRE property is set with Check Code, and not applied during field creation.
Entering a specific criterion resets the field to its original state by using the SET-
NOT-REQUIRED command.
57
Epi Info – Guide to Web Survey
You can setup the Enter Data application for complex operations not listed in this
languages.
58
Epi Info – Guide to Web Survey
consider Sunday as the first epidemiological day of the week. Others consider the
By default, Epi Info™ 7 marks Sunday, the beginning of the epidemiological week.
Modify the parameter for the EpiWeek function, changing the first day of the
epidemiological week.
Use the EpiWeek function if the year doesn’t matter. Using EpiWeek creates a
numeric value stored in a numeric field. EPIWEEK requires the date parameter.
Weeks are calculated based on the date (i.e.: year). View the epidemiological week
syntax below:
The Check Code shown below, calculates EPIWEEK into the SurveillanceWeek
field. It requires a value entry in OnsetDate.
Change the Check Code syntax if the first day of the epidemiological week doesn’t
start on Sunday. In the example, set the epidemiological week to Monday (i.e.,
59
Epi Info – Guide to Web Survey
Check Code syntax must match the field type. Here are some examples of proper
60
Epi Info – Guide to Web Survey
61
1