GetVariable from function in visual basic script

I am using the matlab automation server to call a function from a vb script
Result = Matlab.Execute("z=first([2 7],[1 5])") this is a function that ads the values of the 2 vectors and this works
Matlab.GetVariable("z","base") But when i try to get the variable from this function, i get the following error
error: cannot use quotation marks when calling a sub value
Does anybody knows what seems to be the problem with this? Or is not possible to get a variable from a function
thanks in advance

 Accepted Answer

Friedrich
Friedrich on 10 Apr 2013
Edited: Friedrich on 10 Apr 2013
Hi,
when I do this it works fine:
Set ml = CreateObject("MATLAB.application")
ml.Execute ("z = rand(1)")
Val = ml.GetVariable("z", "base")
msgbox Val
Val then contains the value of z (choosed rand(1) to get one value only so that i can display it easily). What is your full code?

4 Comments

This is my code
Set MatLab = CreateObject("Matlab.Application")
Dim Result
Dim C
MatLab.Execute("cd('C:\Users\Gino\Documents\MATLAB')")
Result = Matlab.Execute("z=first([2 7],[1 5])")
C = Matlab.GetVariable("z",base)
the function first is a function that just ads the 2 vectors
The program I use to to test my code is vbsEdit, wich is for VB script
If this is really your code then you have an error in the GetVariable call. You pass in base as second argument, whereas it needs to be "base". But you do wrote it correctly in your intial post, so I assume its simply a typo.
What happens when you run your .vbs file outside of the vbsEdit? Since .vbs is a known Windows format, a simple double click starts it.
You were right, it does seem to work now
I place the output in C, but what datatype gives the Get.Variable standard? Because printing C in a txt file seems not to be possible
Look at the IDL signature:
HRESULT GetVariable([in] BSTR varname, [in] BSTR workspace, [out, retval] VARIANT* pdata)
It's a Variant. When you like to put some values into a file, i would do it from the MATLAB side because its more easy than doing it in VBS.

Sign in to comment.

More Answers (0)

Categories

Asked:

on 10 Apr 2013

Community Treasure Hunt

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

Start Hunting!