Solved

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

Posted on 2006-10-31
15
677 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Industry Leaders: 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!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

732 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