Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can GUI respond to events in another program? 9

Status
Not open for further replies.

ctlin

Technical User
Apr 17, 2002
77
US
i'm trying to build a front end for a fortran program. you guys helped me get info going from VB into the fortran program yesterday... is there anyway it can go the other way?
is there such thing as having a Fortran program trigger a system event at certain points during execution and VB responding to those? what i need is a way for VB to know when it needs to send input to Fortran. Thanks in advance
 
The only thing I can think of is the RaiseEvent command...

If there is some way to make the fortran program trigger a RaiseEvent. Perhaps if you encapsulate your Fortran into a VB Class then this would be possible.

Or encapsulate the fortran into an activeX dll or something.....

I'm assuming here that you can make activeX calls from Fortran. In which case this would be possible......

Hope this helps some....

Martin If the sky is blue and the Sun is yellow.... Why isn't the air Green?
 
Just jumping in here...

What sort of Fortran program is it? GUI? Command-line?

If the Fortran program is command-line based I would use the capabilities of Windows Script Host 5.6

You create a WShell object in your VB program.

You use the Exec method of WShell to run the Fortran program.

Exec returns a WshScriptExec object.

You use the WshScriptExec object's StdIn and StdOut properties to "talk to" the Fortran program: read and interpret prompts from the Fortran program, and write "inputs" back to the Fortran program.

Forget about SendKeys.

Of course if this is some sort of GUI Fortran - well I'm sorry I said anything <grin>.
 
yes, it is a command line run Fortran program. excellent, i was hoping that there would be some way to do this completely in VB. if there's anything worse than trying to go through and rewrite other people's code, it's trying to rewrite other people's Fortan code.
with that in mind, please help me with my code (=

so i downloaded &quot;Windows Script 5.5&quot;. included in the package is Windows Script Host 2.0. i hope that this is the right file.

How exactly do I call these?:
&quot;You create a WShell object in your VB program.
You use the Exec method of WShell to run the Fortran program.
Exec returns a WshScriptExec object&quot;

Our office has only one crappy VB book and someone else has it at the moment. Thanks for the help.

FYI,
right now i am using

somevariable = Shell(&quot;c:\theprogam.exe&quot;)

to make the program run and then sendkeys to type in stuff... quite primitive, yes.
 
do i ever need to write a script (wsf) file in this? how does VBscript vs WSF fit into this? which do i use and where?
 
Don't waste your time with the Scripting Host stuff. The STDIN, STDOUT and STDERR only works properly if the file you are execing is a script of some sort itself (e.g .bat, .vbs, etc,)

There is, however, a completely VB solution for this - reading and writing the STDIN and STDOUT of a command line application. There are some API calls (naturally!), but no additional object libraries are involved. I knocked up a very rough and ready demo this afternoon. If you are still interested I'll try and find a little time to tidy it up into a presentable form.
 
strongm - still very interested. that's the impression i got about script hosting from reading so i wasn't sure how it would be able to read a Fortran command line window. i'm looking forward to learning some api calls... thanks.
 
so how does vb read the stdout of a command line program differently than WSH? i wasn't even aware that you could read the stdout of a different window- does this work, say if i wanted to read from a telnet window? any window that is command line based?
 
<ahem> Sort of. The big problem is that various so-called 'console' (or command line) applications can actually write to the console in various different ways (eg they can use STDIN, STDOUT and STDERR; or they can use the various Read- and WriteConsole functions; or they can write directly to a memory buffer). Sometimes they even use a mixture of methods. So, if you don't know how the application is communicating with the console it can be difficult to gain complete control of them.

The example I've been working on is designed to work with apps that use the standard IO streams.
 
just so i'm clear on this- anything that looks like a dos/command window with only text should be able to work with API calls? the program i'm using isn't an exe (fortran compiles to a .bsf file) but still runs in one of the aforementioned windows.

if it helps at all, the fortran program uses:

write(*,*) 'Enter your selection'

-sounds like a pretty standard call, but who knows how complicated/nonstandard they could make it...

thanks again for the help... i'm reading up on api in preparation for your example.
 
I am also looking forward to the conclusion of this thread. Although I have no need for such a thing at the moment, it sounds interesting.

-Matt
 
I'm still having trouble getting reliable reading of the output (although can successfully send data). Don't move that dial...
 
wow- sounds like quite a program. staying tuned...
 
Heh!

The thing is that it is not particularly simple. If it was, you could just do a quick Google (or similar) search and find a convenient solution. But there are not any out there.

My feeling is that what I want to do is produce a worked example, including some of the thinking behind it. And right now I'm not completely happy with my current solution, so I need to find some time to worry away at it.

This means that I will probably be a couple of days, since RL work looks like getting in the way for a while (and documenting the thought process/solution is fairly time-consuming).

If people are still willing to bear with the situation, I'll try and come up with something vaguely satisfying. If nothing else, some of the thoughts ought to get others thinking as well; there are lots of bright people in this forum...
 
could you give me a hint as to what API calls i need to be working with to read the stdout? i'm fairly new at VB and even newer at API. don't worry about writing a whole program or anything anytime soon- i just need a push in the right direction. (but am still eagerly waiting for the full glory of strongm's solution to unveil, heheh) thanks again.
 
A hint? Well, you need to use anonomous pipes to redirect STDIN, STDOUT and STDERR and then get the console application to use those redirected handles. Of course you first have to deal with the fact that a VB application doesn't actually have STDIN, STDOUT or STDERR...

I now have a completely working solution, but I'm in the wrong office to post it at the moment (plus it doesn't have the commentary yet). Hang in there...
 
You can simply use the SendMessage() API to send messages back and forth between applications - would this be what you need?
 
cclint-
well, the problem is one of the programs is fortran which i don't have(read: don't want) control over, so i can't get it to send stuff to the GUI. i need my VB to read stuff from a dos-like window without help from the dos-like window end.

strongm-
no problem, i'll hang around as long as it takes. you should get some sort of prize for this heheh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top