Object Variables
You can use object variables in expressions. An ordinary variable can be thought of as a name for a location in the computer's memory that holds data. An object variable is a name for a location in the computer's memory that holds a reference (or pointer) to an object.
To use object variables in the Map window, declare and instantiate an object (as in the BeforeTransformation event). Then, create a reference to the object.
Use the New keyword with internal objects (DJIMPORT, DJEXPORT, DJFIELD, DJRECORD).
Set MyObject = New DJIMPORT "Access 97"
Note: Connector name, in this case "Access 97", must be exactly the same as it is listed in the Map window. For example, typing "Access" does not work.
Use the object, then release it by using the AfterTransformation event:
Set MyObject = Nothing
Note: For object variables only (not for ordinary scalar variables, nor arrays), clear the reference to the object using the Set and Nothing keywords.
See Also
Declaring Object Variables
Assigning a value to an object variable must be done using the Set operator. Assignment is the only action you can take with an object variable alone. If you want to do something else with the object, use one of the object properties for the object type.
The examples below show several scenarios for declaring object variables.
Example 1
'This example declares the variable F as a DJField type of transformation-wide object variable.
Private F As DJField
Example 2
'This example declares the variable F as a DJField type of local object variable.
Dim F As DJField
Example 3
'This example assigns the object variable F to be a pointer to the default field (generally the first field in a source file).
Set F = FieldAt("/SOURCE/R1/MyField")
Internal Object Variables for Mapping
The internal object variables available in the Map window include: djimport, djexport, djrecord, djfield, err, and sys.
You must declare object variables before you set them. However, you cannot set the err and sys variables.
For the object properties you can use with these variables, see
Script Objects.
Example
'Place this expression in an Execute action at the BeforeTransformation event.
Private x As DJField
x = FieldAt("/SOURCE/R1/MyField")
x.Value
'This returns the data in the default (usually first) source field.
Note: Mapping does not support object variable arrays.
Err Object Variable
The Err object variable contains a reference to a system object used to provide information on EZscript exceptions.
Tip... The Err object variable only exists for EZscript. Use the
Project Object to retrieve the error count and return codes for other process steps.
The Err object properties are accessed in the same way as with Visual Basic. Err.Number is the error number; Err.Description is the error description, and so on. These properties are read-only.
Many run-time errors are trappable using run-time error trapping statements, such as
On Error GoTo Statement.
To find out what error was trapped, use the Err object. Err object properties are reset every time a run-time error trapping statement is executed.
Example of Using the Err Object
When the EZscript code below is executed, the following error message appears:
Error 114 DivideByZero(StackTrace.ezscript:2)
StackTrace.ezscript:
'Define a function that returns a Divide By Zero exception:
Function DivideByZero(a)
Return a / 0
End Function
'Define a function to call DivideByZero, trap the exception, and print a stack trace:
Function test()
On Error GoTo err_Test
Return DivideByZero(10)
err_Test:
LogMessage("Info","Error & Err.Number)
LogMessage("Info",Err.StackTrace)
End Function
'Execute the test function:
test()
Last modified date: 07/26/2024