Declaring Variables
Variables are distinguished from attributes in that they are not specifically related to the Context object. Variables are defined and accessible within a particular scope. That is, variables are temporary, and are discarded after the scope (e.g., Procedure) in which they are defined is exited.
NOTE: Variables declared in the User script are defined globally, so their scope spans the entire program.
A Dim statement within a Procedure, subroutine or function declares variables locally to that Procedure, subroutine or function. Variables declared within a particular scope are not “seen” outside of that scope, and once that scope is exited, the variable is discarded. For example, a variable declared at the trial level with the Dim command is discarded after the trial Procedure is completed, and is not automatically logged in the data file. A variable must be set as an attribute of the Context object in order to be logged in the data file.
Variables declared at the top level of the experiment (i.e., global variables) must be declared on the User tab in the Script window using the Dim statement. Global variables may then be initialized within the structure of the experiment using an InLine object. Most commonly, the initialization of global variables would be entered in an InLine object at the beginning of the experiment structure. Variables declared globally may be accessed at any point in the structure of the experiment (i.e., their scope includes the entire experiment).
Naming Variables
Variable names must start with a letter, and may contain letters, digits and the underscore character1. Punctuation is not allowed, although the exclamation point (!) may appear in a position other than the first or last character2. Variable names may not exceed 80 characters in length, and cannot be from among the list of reserved words (see the Keywords topic in the E-Prime Command Reference for a listing of reserved words in the E-Basic language).
1 E-Objects named in E-Studio do not permit the use of the underscore character.
2 If the exclamation point is entered as the last character, it is interpreted as a type-declaration character by E-Basic.
Rules
-
Must begin with a letter
-
Numbers are acceptable but may not appear in the first character position
-
Punctuation is not permitted, with the exception of the underscore one character and the exclamation
point (see above paragraph for details) -
Illegal characters are @#$%^&*(){}-+[]=><~`:;
-
Spaces are not permitted
-
Maximum number of characters is 80
-
Cannot duplicate a reserved word
-
Cannot use the same name more than once within the same scope
-
The backslash character (“\”) may not be used. This is an escape character within E-Basic, which signals E-Basic to interpret the character following the backslash as a command (e.g., “\n” would be interpreted by E-Basic as “new line”).
As long as the rules above are followed, variables may be named almost anything. However, it is highly recommended that the user follow a logical naming scheme, because this makes programming much easier in the long run. Specifically, give variables logical names to quickly remember their purpose. If the variable is nothing more than a counter, give it a single letter name such as “i,” “j” and so on. If the variable’s purpose is to keep track of a participant’s date of birth, name the variable something like “participant_birthdate” rather than “xvariable.”
Next Article: SCRIPTING: User Script Window [22879]
Previous Article: SCRIPTING: Attributes [25772]
Comments
0 comments
Please sign in to leave a comment.