Solved

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

Posted on 2006-10-31
15
667 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
  • 3
  • 3
  • 3
  • +5
15 Comments
 
LVL 142

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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now