Siebel VB Language Reference > VB Language Reference >

Global Statement


This standard VB statement declares Global variables for use in a Basic program.

Syntax

Global variableName [As type] [,variableName [As type]]  ...

Argument
Description

variableName

A variable name

type

The variable's data type

Returns

Not applicable

Usage

In Siebel VB, a Global variable must generally be declared in every module from which you wish to access that variable. Declare Global variables in the (general) (declarations) section for the module.

Basic is a strongly typed language: variables must be given a data type or they are assigned a type of variant.

If the As clause is not used, the type of the global variable can be specified by using a type character as a suffix to variableName. The two different type-specification methods can be intermixed in a single Global statement (although not on the same variable).

Regardless of which mechanism you use to declare a global variable, you can choose to use or omit the type character when referring to the variable in the rest of your program. The type suffix is not considered part of the variable name.

The available data types are:

  • Arrays
  • Numbers
  • Records
  • Strings
  • Variants

Arrays

The available data types for arrays are numbers, strings, variants, and records. Arrays of arrays, dialog box records, and objects are not supported.

Array variables are declared by including a subscript list as part of the variableName. The syntax to use for variableName is:

Global variable([ subscriptRange, ... ]) [As typeName]

where subscriptRange is of the format:

[startSubscript To] endSubscript

If startSubscript is not specified, 0 is used as the default. The Option Base statement can be used to change the default to 1.

Both the startSubscript and the endSubscript are valid subscripts for the array. The maximum number of subscripts that can be specified in an array definition is 60.

If no subscriptRange is specified for an array, the array is declared as a dynamic array. In this case, the ReDim statement must be used to specify the dimensions of the array before the array can be used.

Numbers

Numeric variables can be declared using the As clause and one of the following numeric types: currency, integer, long, single, and double. Numeric variables can also be declared by including a type character as a suffix to the name.

Records

Record variables are declared by using an As clause and a type that has previously been defined using the Type statement. The syntax to use is:

Global variableName As typeName

Records are made up of a collection of data elements called fields. These fields can be of any numeric, string, variant, or previously defined record type. For details on accessing fields within a record, read Type Statement.

You cannot use the Global statement to declare a dialog record.

Strings

Siebel VB supports two types of strings, fixed-length and dynamic. Fixed-length strings are declared with a specific length (between 1 and 32767) and cannot be changed later. Use the following syntax to declare a fixed-length string:

Global variableName As String * length

Dynamic strings have no declared length, and can vary in length from 0 to 32767. The initial length for a dynamic string is 0. Use the following syntax to declare a dynamic string:

Global variableName$   

or

Global variableName As String

Variants

Declare variables as variants when the type of the variable is not known at the start of, or might change during, the procedure. For example, a variant is useful for holding input from a user when valid input can be either text or numbers. Use the following syntax to declare a variant:

Global variableName   

or

GlobalvariableName As Variant

Variant variables are initialized to vartype Empty.

Example

This example contains two subroutines that share the variables total and acctno, and the record grecord.

(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

See Also

Const Statement
Dim Statement
Option Base Statement
ReDim Statement
Static Statement
Type Statement

Siebel VB Language Reference