Link to home
Start Free TrialLog in
Avatar of yangye
yangye

asked on

Wrong number of arguments or invalid property assignment error when calling Matlab Com in Visual Basic

I have a very simple mablab com (dll) function produced by matlab "comtool". The matlab .m file is named as  sumtwo.m and looks like:

function c = sumtwo(a,b)
   c= a+b;

I used Matlab comtool to produce a com dll for it, and named it as sumtwolib.dll and assigned a classname of sumtwoclass to it. After I built it, I can see this dll in the visual basic object viewer. I want to call it in Visual basic and see whether it will work or not. I just used a button in my user form, and when I click that button, I want to see the result. But when I run it, I got an error of "run time error 450. Wrong number of arguments or invalid property assignment error". Below is the visual basic code I wrote.

Private Sub cmdSum_Click()
 Dim sum As Integer
 Dim obj_dll
 Set obj_dll = CreateObject("sumtwolib.sumtwoclass")
 sum = obj_dll.sumtwo(1, 2)
 MsgBox sum
End Sub

Could someone kindly help me. Dll and Com are new for me.

Thanks in advance
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

what is the return value of summtwo procedure?
Implemented code for that function?
Avatar of yangye
yangye

ASKER

I have figured out this problem by myself. Where Matlab's Dll function is a little different from others. I did like this:

......
obj_dll.sumtwo(1, sum, 1.0, 2.0)
......

where 1 means only 1 output parameter, sum is the output parameter, 1.0 and 2.0 are two input parameters, respectively. It also shown that this didn't work on integer input parameter. I don't know why, so I just changed them to double.
Avatar of yangye

ASKER

Thanks Richie_Simonetti for your kind reply. The return value of sumtwo function is the sum of the two input parameters. I have figured out how to do it. See my previous comment.
ASKER CERTIFIED SOLUTION
Avatar of bingie
bingie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial