Siebel VB Language Reference > Using Siebel VB > Declaring Procedures and Variables >

Declaring Variables


This topic includes information about using the Declare Variable statement to declare a variable. For more information about this statement and the format and arguments that you can use with it, see Declare Variable Statement.

It is recommended that you place procedure-level Declare Variable statements at the beginning of the procedure.

For information about explicitly declaring a variable, see Force Explicit Declaration Statement.

Determining Variable Scope

You can write code that shares a variable across modules. The following locations where you declare a variable determines the scope of the variable:

  • Declare in a procedure. The variable is local to this procedure.
  • Declare outside a procedure. The variable is local to the module.

If you declare a variable that has the same name as a module variable, then you cannot access the module variable. For more information, see Declare Global Variable Statement.

Specifying the Type When You Declare a Variable

You can specify one of the following types when you declare a variable:

  • Arrays
  • Numbers
  • Records
  • Strings
  • Variants
  • Objects

If you do not specify a data type, then Siebel VB assigns the variant data type to this variable.

If you do not include the As clause, then you can specify the type argument. To specify this argument, you use a type character as a suffix of the variableName argument. You can use both type specification techniques in a single Declare Variable statement. You cannot use them simultaneously on the same variable.

You can write code that omits the type character when your code references the variable. The type suffix is not part of the variable name.

For more information, see About Data Types.

Declaring an Array Variable

The following data types are available for an array:

  • Numbers
  • Strings
  • Variants
  • Records

You cannot write code that uses the Declare Variable statement to declare an array of arrays or an array of objects.

You include a subscript list as part of the variableName argument to declare an array variable. You can use one of the following formats:

Dim variable([[startSubcript To] endSubscript, ...]) As typeName

Dim variable_with_suffix([[startSubcript To] endSubscript, ... ])

Table 10 describes the startSubscript and endSubscript arguments.

Table 10. Start Subscript and End Subscript Arguments
Argument
Description

startSubscript

The index number of the first array element, followed by the following keyword:

To

endSubscript

The index number of the last element of the array.

Specifying Arguments When Declaring an Array

The startSubscript argument is optional. If you do not specify it, then Siebel VB uses zero as the default value. For example, the following statement creates an array named counter that includes elements 0 through 25, for a total of 26 elements. You can use the Set Array Lower Boundary statement to modify the default value:

Dim counter (25) as Integer

The values in the startSubscript argument and the endSubscript argument are valid subscripts for the array.

Size Limits of an Array

You can specify no more than 60 arrays in a parent array. The maximum total number of elements cannot exceed 65,536. For example, the following code is valid because 60 multiplied by 1092 is 65,520, which is less than 65,536:

Dim count(1 To 60, 1 To 1092)

The following code is not valid because 60 multiplied by 1093 is 65,580, which is more than 65,536:

Dim count(1 To 60, 1 To 1093)

Each subscript declares one array that resides in the parent array. If you do not specify the subscriptRange argument, then Siebel VB declares the array as a dynamic array. In this situation, you must use the Declare Array method to specify the dimensions of the array before your code can use it.

Declaring a Number Variable

Can use the As clause and one of the following numeric types to declare a numeric variable:

  • Currency
  • Integer
  • Long
  • Single
  • Double

You can also include a type character as a suffix to the variable name to declare a numeric variable. Siebel VB sets a numeric variable to 0.

Declaring a Record Variable

You can use the As clause and specify a value in the typeName argument to declare a record variable. To define this type, you must use the Type statement before you can specify it in the typeName argument. You use the following format:

Dim variableName As typeName

A record includes a collection of data elements that are fields. Each field can be a numeric, string, variant, or previously defined record type. For more information on accessing fields in a record, see Create Function Method.

Declaring a String Variable

Siebel VB supports the following types of strings:

  • Fixed-length. Declared with a specific length between 1 and 32767. You cannot write code that modifies a fixed-length variable after you declare it. When you create a fixed-length string, Siebel VB fills it with zeros. To declare a fixed-length string, you use the following format:

    Dim variableName As String * length

  • Dynamic. Does not include a declared length. It can vary in length from 0 to 32,767. The initial length for a dynamic string is 0. You can use one of the following formats to declare a dynamic string:

    Dim variableName$
    Dim variableName As String

Declaring a Variant Variable

You declare a variable as a variant in the following situations:

  • If the type of the variable is not known.
  • If Siebel CRM might modify the variable type when the code runs. For example, a variant is useful for holding input from a user when valid input can include text or numbers.

You use one of the following formats to declare a variant variable:

Dim variableName
Dim variableName As Variant

Siebel VB initializes a variant variable to the Empty variant type.

For more information, see Variants.

Declaring an Object Variable

To declare an object variable, you use the As clause and specify a class in the typeName argument. An object variable can reference an object. It can use dot notation to access members and methods of this object. For example:

Dim COMObject As Object
Set
COMObject = CreateObject("spoly.cpoly")
COMObject.reset

You can declare an object as New for some classes. For example:

Dim variableName As New className
variableName.methodName

A Set statement is not required in this situation. Siebel VB allocates a new object when it uses this variable.

You cannot use the New operator with the Basic Object class.

Caution About Declaring Multiple Variables on One Line

CAUTION:  You can declare multiple variables on one line. However, if you do not include the type for each variable, then Siebel VB applies the type of the last variable to all the variables that you declare on this line.

For example, the following code declares all of the following variables as strings:

Dim Acct, CustName, Addr As String

Shared Keyword Allows Backward Compatibility

Siebel VB includes the shared keyword to support backward compatibility with older versions of Visual Basic. You cannot use it in a Declare Variable statement in a procedure. If you use the Shared keyword in a Declare Variable statement in a procedure, then it has no effect.

Siebel VB Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.