|Bookshelf Home | Contents | Index | PDF|
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.
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.
|Siebel VB Language Reference|