PRB: Script Error Occurs When Referencing Non-variant Array This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
This article was previously published under Q165967 SYMPTOMS When a script attempts to reference the elements of an
array returned by a component, the script engine reports: "Object doesn't support this property or method
'<object>.<method>'" CAUSE The VBSCRIPT active scripting engine supplied by Microsoft
only supports the indexing of SAFEARRAYs of VARIANTs. While VBSCRIPT is capable
of accepting arrays of non-variant type for the purposes of boundary checking
and passing it to other automation objects, the engine does not allow
manipulation of the array contents at this time. The JSCRIPT active scripting engine does not provide support for testing the bounds or indexing SAFEARRAYs of any type including VARIANTs. However, JSCRIPT is capable of passing SAFEARRAYs from one automation object to another. RESOLUTION To function correctly with applications and components that
host VBSCRIPT, automation objects should create SAFEARRAYs of VARIANTs.
Non-VARIANT data should be packaged in the VARIANT elements of the SAFEARRAY to
be returned to the VBSCRIPT engine. Scripts written in VBSCRIPT should use the TypeName function to check the data type of a variable. The TypeName function returns the string "Variant()," excluding the quotes, when passed an array of VARIANTs. Scripts written in JSCRIPT should use the typeof operator to test the data type of a variable. The typeof operator returns the string "unknown," excluding the quotes for datatypes unsupported by JSCRIPT. STATUS This behavior is by design. MORE INFORMATION The VBSARRAY is a simple Active Template Library (ATL)
version 2.1 component object that demonstrates this behavior. The component
implements a dual interface Ivbsa that supports three methods: TestBstrs,
TestVariants, and TestPassArray. The first demonstrates the problem by
returning a SAFEARRAY of BSTRs. The second demonstrates the solution by
packaging each of the BSTRs in a VARIANT. The third demonstrates that an array
of non-VARIANT type can be passed from component to VBSCRIPT or JSCRIPT to
component. The data remains intact. Here is the implementation of TestVariants: Here is the JSCRIPT code from VBSARRAY.HTM, the test page included with
the sample, that checks the datatype of a variable:
To demonstrate the problem and the solution, perform the following
steps:
The following files are available for download from the Microsoft Download Center: Vbsarray.exe (http://download.microsoft.com/download/vbscriptedition/sample2/1/w9xnt4/en-us/vbsarray.exe) For
additional information about how to download Microsoft Support files, click the
following article number to view the article in the Microsoft Knowledge Base: 119591 (http://support.microsoft.com/kb/119591/EN-US/) How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most
current virus-detection software that was available on the date that the file
was posted. The file is stored on security-enhanced servers that help to
prevent any unauthorized changes to the file.
REFERENCES Platform SDK Automation Reference Microsoft Visual Basic Scripting Edition Language Reference APPLIES TO
| Article Translations
|


Back to the top
