ObjectType

Creates a WIL variable with a specific COM/OLE variant type.

Syntax:

ObjectType(variant-type, value)

Parameters:

(s) variant-type see below.

(s/i) value value of the variable.

Returns:

(i) a WIL variable with a specific COM/OLE variant type.

 

"variant-type" can be one of the following:

Variant Type

Meaning

NULL

This is like a pointer to NULL.

I1

1-byte signed integer.

I2

Two bytes representing a 2-byte signed integer value.

I4

4-byte signed integer value.

I8

8-byte signed integer value.

R4

32-bit IEEE floating point value.

R8

64-bit IEEE floating point value.

UI1

1-byte unsigned integer.

UI2

2-byte unsigned integer.

UI4

4-byte unsigned integer.

UI8

8-byte unsigned integer.

DECIMAL

A decimal value, specified as a string in the form "#DECIMAL:value".

CY

A currency value, specified as a string in the form "#CURRENCY:value".

DATE

A date/time value, specified as a string in YMD or YMDHMS format

BSTR

A string.

BOOL

A Boolean (True/False) value

ARRAY

If the type indicator is combined with ARRAY by an OR operator, the value is a pointer to a SAFEARRAY. ARRAY can use the OR with the following data types: I1, UI1, I2, UI2, I4, UI4, INT, UINT, R4, R8, BOOL, DECIMAL, ERROR, CY, DATE, and BSTR. ARRAY cannot use OR with VECTOR.

BYREF

If the type indicator is combined with BYREF by an OR operator, the value is a reference. Reference types are interpreted as a reference to data. BYREF can use OR with the following types: I1, UI1, I2, UI2, I4, UI4, INT, UINT, R4, R8, BOOL, DECIMAL, ERROR, CY, DATE, BSTR, and VARIANT. BYREF  cannot be used alone.  BYREF cannot use OR with ARRAY or VECTOR. Separate the two types passed to ObjectType with a vertical bar (|) to form a BYREF  type combination.  The BYREF type can also be used in combination with another type when specifying a COM Automation object method parameter's type by using the BYREF type combination followed by a single colon(:) and then the expression that evaluates to the parameter's value.

DISPATCH

A pointer to an object was specified. This object is known only to implement IDispatch.

UNKNOWN

A pointer to an object that implements the IUnknown interface. You can only specify the value 0 to create a NULL VT_UNKNOWN variant.

 

 

The "variant-type" may be preceded by the prefix "VT_", so for example you could specify either "BOOL" or "VT_BOOL".

ObjectType can convert WIL arrays and binary buffers to variant safearrays of a specific type. Request conversion by prepending "ARRAY|" to the variant element type in the first parameter.  The function's second parameter should contain a WIL array, a Variant safearray or a binary buffer when using the "ARRAY|" specification. The special type specification "ARRAY|VARIANT" can be used to convert WIL arrays already containing multiple variant types into a safearrays of type VARIANT.

When a COM/OLE method or property returns a value that is one of these supported variant types, WinBatch now retains the variant type for the returned variable, without having to use the ObjectType function. However, if you subsequently assign a new value to that variable using a regular WIL assignment operator, the variant type information will be lost. For example:


visible = ExcelApp.Visible
ExcelApp.Visible = visible
The variable "visible" is returned as a VT_BOOL, and is still a VT_BOOL when it is passed back To the COM/OLE object. But here:
visible = ExcelApp.Visible
visible = 0
ExcelApp.Visible = visible
The assignment "visible = 0" causes "visible" To become an ordinary WIL integer, without a variant type. In that Case, If you wanted it To be a VT_BOOL you would need To use ObjectType:
visible = ObjectType("BOOL", 0)
ExcelApp.Visible = visible
Or simply:
ExcelApp.Visible = ObjectType("BOOL", 0)
Example:
#DefineFunction PrintGraphic(File)
; This can be used to Print: HTML files or
; Graphics files (i.e., BMP TIFF JPG JPEG GIF)
; Requires Windows 2000 or later.
If WinVersion(1) != 5
   Message("Error","This function is not supported on this Windows platform")
   Return(0)
EndIf
objBrowser = ObjectOpen("InternetExplorer.Application")
objBrowser.addressbar = @FALSE
objBrowser.statusbar = @FALSE
objBrowser.menubar = @FALSE
objBrowser.toolbar = @FALSE
objBrowser.visible = @FALSE
objBrowser.navigate(file)
While @TRUE
   If objBrowser.ReadyState == 4 Then Break
   TimeDelay(1)
EndWhile
objBrowserDoc = objBrowser.Document
objAll = objBrowserdoc.all
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
PRINT_DONTBOTHERUSER = 1
PRINT_WAITFORCOMPLETION = 2
pvaIn = ObjectType("I2",PRINT_WAITFORCOMPLETION|PRINT_DONTBOTHERUSER)
pvaOut = ObjectType("NULL","")
objBrowser.ExecWB(OLECMDID_PRINT,OLECMDEXECOPT_DONTPROMPTUSER,pvaIn, pvaOut)
;Give the browser enough time to print before closing the object
TimeDelay(1)
objBrowserDoc = ""
objAll = ""
objBrowser = ""
Return(1)
#EndFunction
file = "c:\temp\test.jpg"
If FileExist(file)Then PrintGraphic(File)
Else Message("Error","Unable to locate file. Check file path.")
Exit
See Also:

COM/OLE, ObjectTypeGet