Create Function Method
The Create Function method creates a function. It returns to the caller when it encounters an End Function statement or an Exit Function statement. It returns the value that the expression argument calculates.
Format
[Static] [Private] Function name([[Optional ]argument
[As type]][, ... ]) [As funcType]
name = expression
End Function
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
name |
The name of the function. |
argument |
The argument to pass to the function when Siebel VB calls it. For more information, see Create Subroutine Method. |
type |
The data type of the argument. |
funcType |
The data type of the value that the function returns. |
Usage
For information about the static and private keywords, see Create Subroutine Method.
A Visual Basic procedure passes values through reference. This means that if a procedure assigns a value to an argument, then it modifies the variable that the caller passes. You must use this feature with caution. For more information, see Pass Values Through Reference.
For information about declaring optional arguments, see Create Subroutine Method.
Specifying the Type
Specifying the type character when you use the Create Function method is optional. A function can create and return a single value of a type that you specify. The data type of the value in the name argument determines the type of the return value. You can do one of the following to specify the data type:
Use a type character as part of the name.
Use the As funcType clause.
If you do not use one of these formats, then Siebel VB uses the default data type, which is variant.
Specifying the Return Value
You use the following format to specify the return value for the function name:
name = expression
where:
name is the name of the function
expression evaluates to a return value
If you do not include this code, then Siebel VB returns one of the following values:
0 for a numeric function
null string ("") for a string function
An Empty variable type for a return type of variant. For more information, see Variants.
You can use the Sub statement to define a procedure that does not include a return value.
Caution About Writing a Custom Function or Subroutine
If you create more than one function or subroutine in the general declarations section, then you must make sure that any other custom function or subroutine that you create that calls this function or subroutine occurs before the procedure that calls it. Otherwise, you cannot compile your procedures.
You cannot create a custom function or custom subroutine in a method or event that displays in Siebel Tools. You can create a custom function or custom subroutine in the general declarations section in the script of a method. If your function or subroutine must be available throughout the code, then you can use a PreInvokeMethod method or an external DLL file to store them in a central location. For more information, see doc ID 476501.1 on My Oracle Support.
Example
The following example declares a function that the subroutine calls. The function performs a calculation on the value sent to it. This calculation modifies the value of the variable:
(general) (declarations)
Option Explicit
Declare Function Calculate(i as Single) As Single
Function Calculate(i As Single)
i = i * 3 + 2
Calculate = i
End Function
Sub Button_Click
Dim x as String
Dim y As Single
x = 34
y = val(x)
Call Calculate(y)
End Sub
For other examples, see Declare Procedure Method, and Go To Statement.