Why do I receive a type mismatch error when I call my MATLAB Builder for COM created COM object from VBScript?

2 views (last 30 days)
I wrote a simple VBScript that calls a function (mymagic) from a COM object built using one of the examples in the documentation. I received an error about a type mismatch when executing the "WScript.Echo" function to print out the results.
Dim oMag
Set oMag= CreateObject("Mag.Magclass.1_0")
Dim oResult
Call oMag.mymagic(1, oResult, 10)
WScript.Echo(cstr(oResult(1, 1)))

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
When calling a COM object in VBScript you need to make sure that you set the MWFlags for the COM object to specify cell array for the output. Also, you must use an enumeration (the enumeration value for a cell array is 2) to make the specification (rather than specifying mwArrayFormatCell).
The following code shows how to accomplish this:
obj.MWFlags.ArrayFormatFlags.OutputArrayFormat = 2
The reason for this requirement is that VBScript supports only SafeArrays of Variants; VBScript does not handle SafeArrays of doubles. Unless you specify the output as an array of Variant, MATLAB Builder for COM generates an array of doubles.

More Answers (0)

Categories

Find more on COM Component Integration in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!