Summary: Discusses the differences between VBScript and JScript arrays.
I am trying to return array from within an HTML dialog box, that uses JScript, using RhinoScript's HtmlBox function, but I always get an error. What's up with that?
The problem is that JScript arrays are objects but VBScript arrays are not.
A VBScript array is:
Whereas a JScript array is:
As you might expect, VBScript and JScript arrays have completely different implementations behind the scenes. A JScript array is basically just a simple extension of the existing JScript object infrastructure, which is implemented as a hash table. A VBScript array is implemented using the SAFEARRAY data structure, which is just a structure wrapped around a standard “chunk of memory” C-style array.
Since all the COM objects in the world expect VBScript-style arrays and not JScript-style arrays, making JScript interoperate with COM is not always easy.
Occasionally a VBScript routine will pass an array as one of its parameters or as its return value. You can call such a routine from JScript, but must convert the VBScript array into a usable JScript array. To do so, create a VBArray object in your JScript function and convert it to a JScript array using toArray. Note, because JScript does not support multidimensional arrays, if the original VBScript array was multidimensional, the toArray method converts it to a single-dimension JScript array.
The following example includes a VBScript script that creates an array and a JScript script that illustrates how to get and use the array:
Unfortunately, the reverse is not possible: You cannot convert a JScript array into a VBScript one. If you're faced with a JScript routine that passes an array, you have these options: