User`s guide

E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 157
Thus entered in the User Script window, the DoMean function may be used at any time during the
experiment. The CalcMean InLine object below calls the DoMean Function to calculate the mean
of 5 randomly chosen numbers.
Dim total As Double
Dim count As Integer
Dim i As Integer
Dim next_val As Integer
total = 0
count = 5
For i = 1 To count
next_val = Random (1, 20)
MsgBox "Value #" & i & ": "& next_val
total = total + next_val
Next i
MsgBox "The total is " & CStr(total) & "\n" &_
"The count is " & CStr(count) & "\n" &_
"The mean is " & DoMean (total, count)
4.6.4 Additional Information
For more details concerning E-Basic, refer to Chapter 2-E-Basic in the E-Prime Reference Guide.
The complete E-Basic scripting language is fully documented in E-Basic Online Help. This is
accessible via the Help menu within E-Studio.
4.7 Programming: Advanced
Before moving to this section, be comfortable with working with variables and data types. This
section introduces the use of arrays and user defined data types. These are very powerful
features, but understanding the basics is essential.
4.7.1 Arrays
It is often the case that multiple pieces of information need to be used as a single variable. The
best way to handle this is through the use of an array. An array is a storage unit for many items
of the same type. The storage unit is comprised of multiple items of one type, each being stored
in their own index within the array. Think of it as a filing drawer that may contain many files in a
specific order which all pertain to a single topic. The array would be the drawer while the
individual files within would be the indices.
4.7.1.1 Declaring Arrays
To work with an array, refer to the name of the array and the index. An array can be of any data
type, but can only hold a single data type. Specifically, declare an array that holds strings and an
array that holds integers, but an array cannot hold both strings AND integers. However, this is
easily remedied because users may declare arrays of variant data type, which holds any kind of
data. Be careful though; since variant data typically is more memory intensive than other data
types, an array of variants can easily become overwhelming overhead. Use this option wisely.
As with any variable, before using it, first declare and initialize it. The declaration of an array is
similar to any other variable. The Dim statement is used, and the only significant difference is the
dimensions value.