Siebel VB Language Reference > Siebel VB Language Reference >

Sub...End Sub Statement


This standard VB construct defines a subprogram procedure.

Syntax

[Static] [Private] Sub name [([Optional] parameter [ As type] , ...)]
End Sub

Argument
Description
name
The name of the subprogram
parameter
A list of parameter names, separated by commas
type
The data type for parameter

Returns

Not applicable

Usage

A call to a subprogram stands alone as a separate statement (read Call Statement). Recursion is supported.

The data type of a parameter can be specified by using a type character or by using the As clause. Record parameters are declared by using an As clause and a type that has previously been defined using the Type statement. Array parameters are indicated by using empty parentheses after the parameter. The array dimensions are not specified in the Sub statement. Every reference to an array within the body of the subprogram must have a consistent number of dimensions.

If a parameter is declared as optional, its value can be omitted when the function is called. Only variant parameters can be declared as optional, and optional parameters must appear after the required parameters in the Sub statement. To check whether an optional parameter was omitted by the user, use the IsMissing function (read IsMissing Function). For more information on using named parameters, read Named Arguments and Call Statement.

The procedure returns to the caller when the End Sub statement is reached or when an Exit Sub statement is executed.

The Static keyword specifies that the variables declared within the subprogram retains their values as long as the program is running, regardless of the way the variables are declared.

The Private keyword specifies that the procedures are not accessible to functions and subprograms from other modules. Only procedures defined in the same module have access to a Private subprogram.

Basic procedures use the call by reference convention. This means that if a procedure assigns a value to a parameter, it modifies the variable passed by the caller.

Use Function rather than Sub (read Function...End Function Statement) to define a procedure that has a return value.

CAUTION:  You cannot write your own functions or subprograms directly in the methods and events exposed in Siebel Tools. You can write functions and subprograms in the (general) (declarations) section of a given method script. However, if you want your routines to be available throughout the program, you can use the Application_PreInvokeMethod or an external DLL file as a central place to write them. For details, read Siebel Technical Notes #207 and #217.

If you create more than one function or subprogram in the (general) (declarations) section, be sure that any function or subprogram that may be called by other user-defined functions and subprograms appears before the procedure that calls it. Otherwise, you can not compile your procedures.

Example

This example is a subroutine that uses the Sub...End Sub statement.

Sub Button1_Click
   `Hello, World.
End Sub

See Also

BusComp Method
Dim Statement
Function...End Function Statement
Global Statement
Option Explicit Statement
Static Statement


 Siebel VB Language Reference
 Published: 18 June 2003