User`s guide

E-Prime User’s Guide
Chapter 4: Using E-Basic
Page 155
Dim stringVal As String
stringVal = "This is the value of the string."
If the expression extends past a single line, the expression statement must be divided into
separate strings, which are concatenated. The ampersand (&) is used for this purpose. No
linefeeds or carriage returns are included in the concatenation of strings, unless the new line (\n)
character is included.
stringVal = "This is the value of a very long string "&_
"extending over more than one line. The "&_
"individual parts will be joined to form "&_
"a continuous display." &_
"\n\nThis will be displayed two lines lower"
Variables themselves may be used in expression statements. For example, in an assignment
statement, the current value of a variable could be used to set the value of another variable.
Dim i As integer, j As Integer, k As Integer
j = k * i
Rather than a literal assignment, in this case, the current values of the "k" and "i" variables are
determined, and those values are used to calculate the value of "j.” Or a variable may be used to
pass information to a command or function. For example, the value of stringVal defined above
could be used with the MsgBox command to display the intended string.
MsgBox stringVal
4.6.1.4 Constants
A constant is used when requiring the use of a value that does not change. Users could
technically use a variable to hold the value, but it makes more sense to use a constant because it
cannot be modified. To declare a constant, use a Const statement in the same manner a Dim is
used to declare a variable. The only difference is that a value is specified immediately after the
data type.
Const speed_of_light As String = "Really, really fast!"
Const exercise As Boolean = True
4.6.2 Writing Subroutines
Subroutines are composed of a series of commands combined into a unit. This unit may then
be run by a call to the subroutine from within an InLine object. A subroutine is defined using the
Sub…End Sub statement. For example, a simple subroutine may be created to "clear" the
background of a Canvas object to a particular color.
4.6.2.1 Example: Clear the screen to the current color
In the script below, the ClearToRed subroutine sets the fill color to red, and then uses the Clear
command to clear the screen using the current FillColor setting. The script should be entered on
the User script tab in the Script window. Once defined, the subroutine need simply be referred to
by name in order to launch it.