Variable and Function Naming Conventions
When naming functions, variables, and subroutines, there are a few rules and considerations that need to be applied.
Must be less than 256 characters. Variable, function, and subroutine names must be less than a byte (256 characters) in size.
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. |