Call statements
Call statements cause object methods to be called.
Syntax
variable.method (argumentlist)
Arguments
variable
A variable that contains an object. If the variable is not an object, the call statement represents a dotted function call.
method
A method exposed by the object.
argumentlist
Optional. A comma-separated list of variables, arrays, or expressions to pass to the method.
Remarks
The methods available on an object and the required arguments for each method are detailed in the object model documentation.
Any return values from methods executed in call statements are ignored. An assignment statement should be used if the return value is required elsewhere in the script.
mrScriptBasic uses the following rules to differentiate between object method calls and dotted function calls:
If
|
Then
|
variable is an object, method exists
|
The method is called on the object.
|
variable is an object, method does not exist, but a function of the same name does exist
|
The function is called. Unless the function takes an object as its first argument, the default method or property for the object is used to get the value. If the default method or property returns an object, then the default method or property is in turn called on the returned object until a simple value is returned. If the function requires an identifier name, the Name method is called on the object. If the Name method does not exist, or there is no default method or property, an error is generated.
|
variable is an object, method does not exist, and a function of the same name does not exist
|
An error is generated.
|
variable is not an object, and a function does exist
|
The function is called, with the value of the variable being passed as the first argument to the function.
|
variable is not an object, and a function does not exist
|
An error is generated.
|
Several methods or functions can be called in a single line of script.
Note In Visual Basic and VBScript, you can optionally prefix the call statement with the Call keyword. However, the use of the Call keyword is not valid syntax in mrScriptBasic.
Examples
Simple method call on an object
This example first uses the
CreateObject function to create an instance of an Excel Application and then calls the
Workbooks.Add method to create a Workbook object.
Set statements are used so that the objects can be used in the script.
Dim xlApp, xlWorkbook
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = true
Set xlWorkbook = xlApp.Workbooks.Add()
Simple method call with an assignment statement
This example creates a FileSystemObject and then calls its CreateTextFile method to create a text file object. A Set statement is used so that the text file object can be used in the script.
Dim fso, txtfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtfile = fso.CreateTextFile("errors.txt", True)
Dotted function call
This example calls the
Len function to test whether the respondent selected more than one response to the
Gender single response question.
If Gender.Len() > 1 Then
...
End If
Two function calls
You can call more than one method or function in a single line of script. For example, this example calls the
Trim and
Left functions. It returns the first four characters in the
name variable after any leading and trailing spaces have been removed.
Trim(name).Left(4)
See also