JScript Array -> VB SafeArray ActiveX Component

NORMAL LEGAL DISCLAIMERS APPLY TO THIS SOFTWARE. DON'T TRY TO RUN NUCLEAR POWER PLANTS, LIFE-SUPPORT SYSTEMS, OR YOUR TOASTER WITH IT.

General Information

This component allows you to convert a JScript array into a Visual Basic (Automation) Array, otherwise known as "Safe Arrays".

The source code is freely available from me, Peter Torr. (If that address fails, try this one, but the first address will get a much quicker response).. It should be available on the web, hanging off the directory http://www.netspace.net.au/~torrboy/code/. The general sort of free-source rules apply - you can do what you want with this code, as long as:

  1. You don't intentionally use, or allow it to be used, for malicious purposes;
  2. You don't make a profit from selling the source code (you may, however, make a profit from the compiled code and / or from providing support);
  3. You give due credit myself, and anyone else who has contributed to the code.

Programming Information

This component is a standard ActiveX DLL, built with Microsoft's ActiveX Template Library (ATL) and Visual C++ 5. It has been marked as "Safe for scripting", but has not been signed.

Instantiation

ProgID
JScriptHelper.JSafeArray
CLSID
{07D04D37-E5BE-11D2-BE17-00400533C717}
Interface
_JSafeArray
IID
{07D04D36-E5BE-11D2-BE17-00400533C717}

Method

ToSafeArray(JScriptArray)
Returns a VARIANT containing a SAFEARRAY.
Parameters:
JScriptArray
A JScript array.

Example Usage

From the sample file "test.js":

// Create object
var oHelper = WScript.CreateObject("JScriptHelper.JSafeArray");

// Create test object
var oTester = WScript.CreateObject("JScriptTester.Test");

// Create JScript Array
var arr = new Array();

// Put some data in the array
arr[0] = "Hello from JScript!";
arr[1] = 1.234;
arr[2] = new Date();

// Call the ToArray method
var arrVB = oHelper.ToSafeArray(arr);

// Call a method that requires a SafeArray
oTester.Test(arrVB);