Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
PRB: Script Error Occurs When Referencing Non-variant Array
Article ID: 165967 - View products that this article applies to.
This article was previously published under Q165967
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>'"
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.
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.
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.exeFor additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591Microsoft 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.
(http://support.microsoft.com/kb/119591/EN-US/ )How to Obtain Microsoft Support Files from Online Services
Platform SDK Automation Reference
Microsoft Visual Basic Scripting Edition Language Reference
Article ID: 165967 - Last Review: August 5, 2004 - Revision: 4.2