Declare Global Variable Statement
The Declare Global Variable statement declares a global variable. It does not return a value. You must declare a global variable in every module from which Siebel VB must access that variable. You declare a global variable in the general declarations section of the module.
Format
Global variableName [As type] [,variableName [As type]] ...
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
variableName |
The variable name. |
type |
The data type of the variable. |
Usage
If you do not include the As clause, then you can add a type character as a suffix to the variableName argument. You can simultaneously use the two different type specification methods in a single Global statement, but you cannot use these methods simultaneously on the same variable.
Regardless of how you declare a global variable, you can choose to include or not include the type character when you reference the variable from another section of code. Siebel VB does not consider the type suffix as part of the variable name.
Formats That You Can Use to Specify the Type of a Global Variable
Visual Basic is a strongly typed language. You must assign a data type to a variable or Siebel VB assigns a type of variant.
The following table describes the data types you can use to specify the type of a global variable. Declaring a global variable is the same as declaring a variable, except where noted in the Format column in the table. The Reference column includes a link to the description for declaring a variable.
Type | Format | Reference |
---|---|---|
Array |
You use the following format to declare a global record:
where:
|
|
Number |
Not applicable. |
|
Record |
You use the following format to declare a global record:
You cannot use the Declare Global Variable statement to declare a dialog record. |
|
String |
You use the following format to declare a global string:
You use one of the following formats to declare a dynamic string:
|
|
Variant |
You use one of the following formats to declare a global variant:
|
Example
The following example includes two subroutines that share the total and acctno variables, and the grecord record:
(general)(declarations)
Option Explicit
Type acctrecord
acctno As Integer
End Type
Global acctno as Integer
Global total as Integer
Global grecord as acctrecord
Declare Sub CreateFile
Sub CreateFile
Dim x
x = 1
grecord.acctno = 2345
Open "c:\temp001" For Output as #1
Do While grecord.acctno <> 0
grecord.acctno = 0
If grecord.acctno <> 0 then
Print #1, grecord.acctno
x = x + 1
End If
Loop
total = x-1
Close #1
End Sub
Sub Button_Click
Dim msgtext
Dim newline as String
newline = Chr$(10)
Call CreateFile
Open "c:\temp001" For Input as #1
msgtext = "The new account numbers are: " & newline
For x = 1 to total
Input #1, grecord.acctno
msgtext = msgtext & newline & grecord.acctno
Next x
Close #1
Kill "c:\temp001"
End Sub