Variable and Function Naming Conventions

When naming functions, variables, and subroutines, there are a few rules and considerations that need to be applied.

Must begin with a letter. Variable, function, and subroutine names must begin with a letter, not a number or special character. Numerous special characters represent data operations, and using any of those characters as a variable's first character would confuse the STATISTICA Visual Basic interpreter. The same could also be said about using numeric characters.

Must be less than 256 characters. Variable, function, and subroutine names must be less than a byte (256 characters) in size.

Must not contain special characters. Variable, function, and subroutine names must not contain characters such as #,&, or ! unless the character is being used as the suffix (see below).

Must not be keywords. Variable, function, and subroutine names cannot be the same as reserved STATISTICA Visual Basic words, such as Function, ElseIf, Nothing, or Spreadsheet. The STATISTICA Visual Basic edit window will automatically highlight all of these terms (Visual Basic keywords blue and STATISTICA Visual Basic keywords deep purple).

May not have spaces in them. Variable, function, and subroutine names must be one word. The two most common ways to combine multiple words in into a single name are:

Dim NumberOfSpreadsheets As Integer

or

Dim Number_of_spreadsheets As Integer

Although not a rule, it is recommended that you also give functions, variables, and subroutines memorable, short names that describes what it represents. The following are a few examples of way to name functions, variables, and subroutines:

'Spreadsheet variable
Dim
MySpreadsheet As Spreadsheet

Set
MySpreadsheet = ActiveSpreadsheet

'Variable that holds a spreadsheet's number of cases

Dim
CaseCount As Integer

CaseCount = MySpreadsheet.Cases.Count

The suffix of a variable or function can use special characters to indicate its data type. For example:

Dim TextString As String
Dim
TextString$

will both create a variable called TextString of the string data type. The latter type is a naming convention that is useful because it allows you to know a variables data type simply by looking at its suffix (instead of having to refer to its declaration). A function can also be declared in the same manner, as the following demonstrates:

Function Add _

(FirstNumber As Integer,SecondNumber As Integer) _
As Integer

Function Add%(FirstNumber%,SecondNumber%)

Both of these will declare a function which will accept two integers and pass an integer value back to the calling function. Note that a subroutine cannot use this naming convention (except for its parameters) because it doesn't have a return type (see STATISTICA Visual Basic Syntax Reference - User-Defined Functions and Subroutines for additional information about functions and subroutines).

The following is a table containing all of the special character suffixes that may be used on variables and functions and which data types they represent:

Character

Data Type

@

Currency - Monetary data type which supports precision up to fifteen decimals.

#

Double - Double precision data type which supports up to fifteen decimals.

%

Integer - Integer data type ranging from -32,768 to 32,768.

&

Long - Integer data type ranging from -2,147,483,648 to 2,147,483,647.

!

Single - Single precision data type which supports up to seven decimals.

$

String - Text string data type.