User`s guide

E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 154
necessary to convert information from one type to another in order to store it in a particular
variable. E-Basic contains several functions for the purpose of conversion between data types.
Function Description
CCur Converts any expression to a Currency.
CBool Converts expression to True or False, returning a Boolean value.
CDate, CVDate Converts expression to a date, returning a Date value.
CDbl Converts any expression to a Double.
CInt Converts expression to an Integer.
Chr, Chr$, ChrB,
ChrB$, ChrW, ChrW$
Returns the character whose ASCII value is charcode.
CLng Converts expression to a Long.
CSng Converts expression to a Single.
CStr Converts expression to a String.
Cvar Converts expression to a Variant.
Hex, Hex$ Returns a String containing the hexadecimal equivalent of number.
Str, Str$ Returns a string representation of the given number.
Val Converts a given string expression to a number.
Note, some functions offer the optional use of the "$" character. When the "$" character is used,
the value returned is a string. When "$" is not used, a string variant is returned.
4.6.1.2 Declaring Multiple Variables
Users are not limited to one variable declaration per line. Multiple variables may be declared on a
single line using only a single Dim statement. However, the user should take care to specify the
data type for each variable declared, even if they are on the same line. Any variable that is not
specifically declared with a data type will be declared as a Variant. In the example below, subject
_dob is declared as a date. Stim is declared as a string and k is declared as an integer. The j
variable is declared as a variant because it is not specifically stated to be any other data type.
Dim subject_dob As Date, j, k As Integer, stim As String
Declaring multiple variables on the same line may save space, but it also increases the likelihood
of human error. A compromise might be to not mix data types within a single line to help organize
variables and reduce the chance of error.
Dim subject_birthdate As Date
Dim j As Integer, k As Integer
Dim stimulus As String, Dim recall As String
4.6.1.3 Initialize and Assign Values
Once a variable is declared, it must be initialized before it can be used. Initializing a variable is
nothing more than assigning it an initial or starting value. Most often the purpose of a variable is
to hold information that is assigned. An assignment statement simply consists of the variable
name followed by an equal sign and then the expression (variable name = expression).
j = 1
In the example above, the counter variable "j" (used in a previous example) is assigned the
expression or value of 1. String values are also assigned using an assignment statement, but the
expression value must be enclosed in quotes.