• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

how to call an exe file from vb and get output values (exe created in matlab)

I have a matlab function:

function output1, output2, output3 = test(a,b)
    output1 = a;
    output2 = b;
    output3 = a + b;
end

which i have compiled into an exe file - test.exe

i wish to call this exe file from my vb6 application and store the 3 returned values into variables in vb.

Can anyone provide me with the vb code to do this?

I need this ASAP, so there are 500 points up for grabs!!!
0
DanM711
Asked:
DanM711
  • 3
  • 3
  • 3
  • +5
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
how does the matlab exe return the data? to the "command prompt"?
0
 
DanM711Author Commented:
when i run the matlab exe, nothing appears at the command prompt. I can get matlab to print the values to the command prompt if i want. Is there a way to get vb to read this? although i'm sure there must be a way to retrieve the values without having to print them out.
0
 
pierrecampeCommented:
what happens if at the command prompt you type
test.exe > c:\test.txt
is there a file 'c:\test.txt' that gets created ?
and does it have the values in it ?
if so you can let your vb program read that file to get at the values

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DanM711Author Commented:
nothing gets written into the file. But i don't want to have to get vb reading files. There must be a way to get the output values....
0
 
pierrecampeCommented:
ok
you say you have a program 'test.exe'
what does that program do ?
how do you get the input values (a,b) into test.exe ? on the command line ?
and how does test.exe give back its output (a,b,a+b) ? to the console window ?

0
 
BrianGEFF719Commented:
>>But i don't want to have to get vb reading files. There must be a way to get the output values....

You can do this using PIPES.

Basically you change the STDIN and STDOUT of a exe when you create the process using CreateProcess (). This allows you to programically send and receive output from CONSOLE based applications, make sense?


Check out this download: (DONT RELY ON THE CODE, IT DOES NOT PROVIDE DECLARATIONS, DOWNLOAD THE WHOLE PROJECT).
http://vb-helper.com/howto_capture_console_stdout.html


Good Luck.
Brian
0
 
CSecurityCommented:
Get this source code:

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=39895&lngWId=1

And write the code in your Matlab app to print the results out (not any other way available!) [except you can add a code in matlab to write output in a file and you read that file]
0
 
ClivousCommented:
Hi,

First of all u must be sure to make a activeX .exe not a standard exe.
Make the test.exe as activeX .exe ( properties -> ProjectType -> ActiveX exe )

Then make sure there are some public functions in the activeX .exe

Example:
public function givemesomeoutput (output1, output2, output3) as double
    givemesomeoutput = output1 + output2 + output 3
end function

Now u can lay a reference in some other vb program to the test.exe ( just browse to the location of the exe )
When u have successfully make a reference to the test.exe, u can call the function givemesomeoutput

Goodluck
Hans
0
 
jmundsackCommented:
If you don't want to use file I/O to communicate with VB, your other option is to use COM or DDE.  According to the MATLAB website, MATLAB is capable of using these technologies, as described in the following reference:

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f27154.html

You might also post this question on the MATLAB forum, to see if someone else has done this before:

http://newsreader.mathworks.com/WebX?14@@/comp.soft-sys.matlab

My guess is there are going to be very few people here on EE who are also MATLAB users.

HTH-Jon
0
 
oleggoldCommented:
can't you just use
shell test.exe > c:\test.txt from inside Your vb function:

Function Shell(PathName, [WindowStyle As VbAppWinStyle = vbMinimizedFocus]) As Double
0
 
BrianGEFF719Commented:
@oleggold,

He doesnt want to have to parse text files for the output of the program.
0
 
pierrecampeCommented:
indeed
and he even doesnt want to tell us how that program gets its input,or how it gives its output
so what do you want to do ?
0
 
BrianGEFF719Commented:
>>so what do you want to do ?

We have to wait until he explains his situation further.
0
 
DanM711Author Commented:
The input is in the call within vb.

i'm guessing that parsing text from a file will slow the vb app.

clivious's approach sounds promising, would be interessted to see the corresponding vb code.

I'm also going to be checking out the approach sent by BrianGEFF719
0
 
CSecurityCommented:
As I said get that code from RAC, that reads Matlab's output that MATLAB writes to comamnd line, then you can process the output
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
  • 3
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now