Is there any general component in the o/s that will convert an array of specific type to array of variant usable in WSH/VBS/JS (cscript, wscript)? RRS feed

  • Question

  • Not sure if this is the proper forum, but I can't find anything closer. The question is related to VBScript/JScript as running in Windows Scripting host (cscript.exe or wscript.exe). Assume that some automation/COM component returns a safearray that contains elements which are typed (e.g. VT_R8 or VT_UI1, VT_I4, etc), perfectly usable in VBA/Excel, C++, Python, etc...

    VBScript and JScript can get a reference to this array but cannot do anything with the elements in the array (Type Mismatch), since the elements in the array are "typed" rather than VT_VARIANT.

    Question: is there some general way to convert this safearray to a safearray of VT_VARIANT, which is usable in VBScript/JScript? Some o/s component? Some clever way to use ADODB.RecordSet or something else? It seems a little surprising that something like this doesn't exist.

    thanks for any help,


    Thursday, September 13, 2018 4:58 PM


  • As you have noted, VBScript and JScript require VT_VARIANT arrays/collections. Typed arrays will not work. There aren't any built-in workarounds that I know of.

    (One way that I've worked around this in the past is to write a wrapper COM object that gets the typed collections and makes them available as variant.)

    In any case, I would recommend switching to PowerShell as much as possible.

    -- Bill Stewart [Bill_Stewart]

    Thursday, September 13, 2018 5:03 PM