Control an outside program and capture its data

G

Guest

Hello,

I need to control a separate program from within Access VBA. Specifically,
I need to
1 Open the program
2 Navigate to a form
3 Populate several text boxes
4 “send†the information with an F12
5 Read the returned information and populate a form within Access with the
info
6 Recognize errors in this process

The dreaded sendkeys appears to work OK for 1-4 but how can I get the
information back? I looked into some VB commands like
“redirectstandardoutput†but the VBA compiler chokes on this code example
from (http://www.devx.com/dotnet/Article/7914/0/page/5)
Could I be missing a reference to run this in VBA or does VBA not support
this. The lines with an asterisk create errors before running the code.
The outside program is written in C+ (I think) and it creates a log file but
the log file is a “powerbuilder†(.PBD) file which looks like it has some
type of encryption??
Thanks for any guidance you can provide!


*Dim myProcess As Process = New Process()
Dim s As String
myProcess.StartInfo.FileName = "cmd.exe"
myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.CreateNoWindow = True
myProcess.StartInfo.RedirectStandardInput = True
myProcess.StartInfo.RedirectStandardOutput = True
myProcess.StartInfo.RedirectStandardError = True
* myProcess.Start()
* Dim sIn As StreamWriter = myProcess.StandardInput
sIn.AutoFlush = True

* Dim sOut As StreamReader = myProcess.StandardOutput
* Dim sErr As StreamReader = myProcess.StandardError
sIn.Write("dir c:\windows\system32\*.com" & _
System.Environment.NewLine)
sIn.Write("exit" & System.Environment.NewLine)
s = sOut.ReadToEnd()
If Not myProcess.HasExited Then
* myProcess.Kill()
End If

* MessageBox.Show("The 'dir' command window was " & _
* closed at: " & myProcess.ExitTime & "." & _
* System.Environment.NewLine & "Exit Code: " & _
* myProcess.ExitCode)

* sIn.Close()
* sOut.Close()
* sErr.Close()
* myProcess.Close()
MessageBox.Show(s)
 
T

Terry Kreft

The example you have been looking at is written in VB.Net, this bears
absolutely no relation to VBA (or indeed VB).

The best way to control an external program is though COM
Alternatively you can use DDE
The most horrible way is using Sendkeys.
 
G

Guest

Terry, thank you for your thoughts. Any suggestions on examples to look at
for controlling non-microsoft products. All I can find is passing info to
and from office products. I have no idea how to find objects, methods, or
properties belonging to a sybase product written in C+.
 
M

marcus.tettmar

Zip said:
Terry, thank you for your thoughts. Any suggestions on examples to look at
for controlling non-microsoft products. All I can find is passing info to
and from office products. I have no idea how to find objects, methods, or
properties belonging to a sybase product written in C+.

You could use a generic automation tool like Macro Scheduler:
http://www.mjtnet.com/macro_scheduler.htm

Using the command line interface automation routines could be
integrated into your own applications.

Marcus
http://www.mjtnet.com
Macro Scheduler for Windows and Software Process Automation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top