Variables

In Scripter, a variable is a symbolic name for a value. A variable name starts with a letter and may contain digits. Variable names cannot be the same as a reserved word. Because the Scripter code window displays variable names in black and reserved words in color, you can see when you have selected a variable name that conflicts with a reserved word.

Variables may be one of several types. The type of a variable determines what kind of data it may contain. See the following table for the possible variable types. In addition to the built-in data types, the Scripter language supports user-defined compound data types, user-defined enumeration types, and user-defined objects (defined in object modules and class modules).

The type of a variable is declared in a DIM statement. The syntax of a DIM statement is:

Dim varname As type

where varname is the name of the variable being declared and type is the variable's data type. Variables not declared in a DIM statement are a variant type, unless the variable name ends with one of the type-definition characters. If a variable name ends with one of the special type-definition characters, listed below, its type is recognized based on this character.

Type

Type-Definition Character

Description of Type

Integer

%

A 16-bit integer value

PortInt

?

(Portable Integer) A 16- or 32-bit integer value

Long

&

A 32-bit integer value

Single

!

A 32-bit floating-point value

Double

#

A 64-bit floating-point value

Currency

@

A 64-bit fixed-point value

String

$

A text string of any length

Byte

(none)

An 8-bit unsigned integer value

Boolean

(none)

A true or false value

Date

(none)

A 64-bit floating-point value

Object

(none)

A reference to an ActiveX object

Variant

(none)

Capable of holding any type of value

Using the DIM statement to declare the variable type is optional. Variables can be used without first being declared in a DIM statement, but this practice is not recommended for any script longer than a few dozen lines. To enforce this policy, an OPTION EXPLICIT statement should be placed at the top of long scripts. The OPTION EXPLICIT statement makes it an error to use any variable without first declaring it. Using this option lets you find typographical errors in variable names before a script is run. Without this option, typographical errors in variable names are usually detected only when the script fails to produce the expected results.

Next: Object Variables

See Also

Introducing Scripter

Object Variables

Array Variables

User-Defined Types

Global Variables

Object Hierarchy

Surfer Object Model