Siebel VB Language Reference > VB Language Reference >

Sub...End Sub Statement


This standard VB construct defines a subprogram procedure.

Syntax

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

Argument
Description

name

The name of the subprogram

argument

A list of argument names, separated by commas

type

The data type for argument

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 argument can be specified by using a type character or by using the As clause. Record arguments are declared by using an As clause and a type that has previously been defined using the Type statement. Array arguments are indicated by using empty parentheses after the argument. 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 an argument is declared as optional, its value can be omitted when the function is called. Only variant arguments can be declared as optional, and optional arguments must appear after the required arguments in the Sub statement. To check whether an optional argument was omitted by the user, use the IsMissing function (read IsMissing Function). For more information on using named arguments, 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 an argument, 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