VBScript and COM (The Array Dilemma)

its my second day to deal with COM and VBScript and i have faced the problem of passing arrays to and from .NET DLL serving as a COM Component, i described how to do this in the previous postA problem arises when trying to return an array from a function or pass array to it

How to reproduce:

  • you have a .NET DLL using it as a COM Object
  • you have a function in a class that returns an array of any type
  • you create an instance of this class using CreateObject
  • you call the function that returns an array
  • test the array using IsArray() and VarType() and Ubound()
  • the object is truly an array and its VarType() denots its type and Ubound() gives its valid size
  • then you an item in the array it will give you error "Type Mismatch" !!

Why:

  • VBScript datatypes are all based on a basic type called "Variant" which may corresponds to the "Object" data type in .NET
  • Its logic that if VBScript can know the array type which it can access, so why when trying to access a certain item in the array it gives "Type Mismatch" !!!!
  • I think that this is due to a diffrence in implementing and viewing the array from the prespective of .NET and the prespective of VBScript
  • Some solutions on the newsgroups said that you must return your datatype as an Object and this worked in some cases
  • The version of the VBScript processor DLL may have also an influnce in producing this problem