Solved

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

Posted on 2006-10-31
15
678 Views
Last Modified: 2016-02-10
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
Comment
Question by:DanM711
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +5
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17845061
how does the matlab exe return the data? to the "command prompt"?
0
 

Author Comment

by:DanM711
ID: 17846315
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
 
LVL 6

Expert Comment

by:pierrecampe
ID: 17846587
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!

 

Author Comment

by:DanM711
ID: 17846860
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
 
LVL 6

Expert Comment

by:pierrecampe
ID: 17846915
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17847075
>>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
 
LVL 17

Accepted Solution

by:
CSecurity earned 500 total points
ID: 17847540
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
 
LVL 1

Expert Comment

by:Clivous
ID: 17848461
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
 
LVL 13

Expert Comment

by:jmundsack
ID: 17848977
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
 
LVL 21

Expert Comment

by:oleggold
ID: 17849939
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17852182
@oleggold,

He doesnt want to have to parse text files for the output of the program.
0
 
LVL 6

Expert Comment

by:pierrecampe
ID: 17853145
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
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 17853166
>>so what do you want to do ?

We have to wait until he explains his situation further.
0
 

Author Comment

by:DanM711
ID: 17854901
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
 
LVL 17

Expert Comment

by:CSecurity
ID: 17856138
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question