Siebel VB Language Reference > Siebel VB Language Reference >

Call Statement


This standard VB function transfers control to a subprogram or function.

Syntax A

Call subprogram_name [(argument_list)]

Syntax B

subprogram_name argument_list

subprogram_name is the name of the subprogram or function to which control is to be passed.

Argument
Description
argument_list
The arguments, if any, to be passed to the subroutine or function

Returns

If a function, its output; if a subprogram, not applicable.

Usage

Use the Call statement to call a subprogram or function written in Basic or to call C procedures in a DLL. These C procedures must be described in a Declare statement or be implicit in the application. Make sure the DLL is present on every Siebel Server.

If a procedure accepts named arguments, you can use the names to specify the argument and its value. Order is not important. For example, if a procedure is defined as follows:

Sub mysub(aa, bb, optional cc, optional dd)

The following calls to this procedure are equivalent to each other:

call mysub(1, 2, , 4)
mysub aa :=  1, bb :=  2, dd := 4
call mysub(aa :=  1, dd:= 4, bb :=  2)
mysub 1, 2, dd:= 4

The syntax for named arguments is as follows:

argname := argvalue

where argname is the name for the argument as supplied in the Sub or Function statement and argvalue is the value to assign to the argument when you call it.

The advantage to using named arguments is that you do not have to remember the order specified in the procedure's original definition, and if the procedure takes optional arguments, you do not need to include commas (,) for arguments that you leave out.

The procedures that can use named arguments include:

Arguments are passed by reference to procedures written in Basic. If you pass a variable to a procedure that modifies its corresponding formal parameter, and you do not want to have your variable modified (that is, if you need to retain the "before" value), enclose the variable in parentheses in the Call statement. This tells Siebel VB to pass a copy of the variable. (This is called passing by value.) Note, however, that generally passing by value is less efficient, and should not be done unless necessary.

When a variable is passed to a procedure that expects its argument by reference, the variable must match the exact type of the formal parameter of the function. (This restriction does not apply to expressions or variants.)

When calling an external DLL procedure, arguments can be passed by value rather than by reference. This is specified in the Declare statement, the Call statement itself, or both, using the ByVal keyword. If ByVal is specified in the declaration, then the ByVal keyword is optional in the call. If present, it must precede the value. If ByVal was not specified in the declaration, it is illegal in the call unless the data type was unspecified in the declaration.

Example

This example calls a subprogram named CreateFile to open a file, write the numbers 1 to 10 in it, and leave it open. The calling procedure then checks the file's mode. If the mode is 1 (open for Input) or 2 (open for Output), the procedure closes the file.

(general) (declarations)
Option Explicit
Declare Sub CreateFile

Sub CreateFile
   Rem Put the numbers 1-10 into a file
   Dim x as Integer
   Open "c:\temp001" for Output as #1
   For x = 1 to 10
      Write #1, x
   Next x
End Sub

Sub Button1_Click
   Dim filemode as Integer
   Dim attrib as Integer
   Call CreateFile
   attrib = 1
   filemode = FileAttr(1,attrib)
   If filemode = 1 or filemode = 2 then
      Close #1
   End If
   Kill "c:\temp001"
End Sub

See Also

Declare Statement


 Siebel VB Language Reference
 Published: 18 June 2003