Siebel VB Language Reference > VB Language Reference >

Declare Statement

This standard VB statement declares a procedure in a module or dynamic link library (DLL).

Syntax A

Declare Sub name [(argument [As type])]

Syntax B

Declare Function name [(argument [As type])] [As funcType]



The name of the subprogram or function procedure to declare


The arguments to pass to the procedure, separated by commas


The data type for the arguments


The data type of the return value of the function


Syntax A: Not applicable

Syntax B: A value of the type funcType, which can be used in an expression.


To specify the data type for the return value of a function, end the function name with a type character or use the As funcType clause shown previously. If no type is provided, the function defaults to data type variant.

Siebel Tools compiles custom functions in alphabetical order. Therefore, when a procedure in the current module is referenced before it is defined, a declaration must be used.

For example, suppose you have created the following subroutines in the (general) (declarations) section of a module:

Sub A
' Calling B
End Sub

Sub B
theApplication.RaiseErrorText "Sub B called"
End Sub

Compilation fails with the message, "Unknown function: B." However, place the statement:

Declare Sub B

before Sub A and the code compiles and runs properly.

The data type of an 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; array dimensions are not specified in the Declare statement.

External DLL procedures are called with the Pascal calling convention (the actual arguments are pushed on the stack from left to right). By default, the actual arguments are passed by Far reference. For external DLL procedures, there are two additional keywords, ByVal and Any, that can be used in the argument list.

When ByVal is used, it must be specified before the argument it modifies. When applied to numeric data types, ByVal indicates that the argument is passed by value, not by reference. When applied to string arguments, ByVal indicates that the string is passed by Far pointer to the string data. By default, strings are passed by Far pointer to a string descriptor.

Any can be used as a type specification, and permits a call to the procedure to pass a value of any datatype. When Any is used, type checking on the actual argument used in calls to the procedure is disabled (although other arguments not declared as type Any are fully type-safe). The actual argument is passed by Far reference, unless ByVal is specified, in which case the actual value is placed on the stack (or a pointer to the string in the case of string data). ByVal can also be used in the call. The external DLL procedure has the responsibility of determining the type and size of the passed-in value.

When a null string ("") is passed ByVal to an external procedure, the external procedure receives a valid (non-NULL) pointer to a character of 0. To send a NULL pointer, Declare the procedure argument as ByVal As Any, and call the procedure with an argument of 0.


This example declares a function that is later called by the main subprogram. The function does nothing but set its return value to 1. For other examples of functions, read Function...End Function Statement and GoTo Statement.

(general) (declarations)
Option Explicit
Declare Function SVB_exfunction()

Function SVB_exfunction()
   SVB_exfunction = 1
End Function

Sub Button_Click
   Dim y as Integer
   Call SVB_exfunction
   y = SVB_exfunction
End Sub

Related Topics

Const Statement
Deftype Statement
Dim Statement
Static Statement
Type Statement

Siebel VB Language Reference Copyright © 2006, Oracle. All rights reserved.