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!

VB Running Other Programs

Status
Not open for further replies.

pds

Programmer
Jul 2, 2001
9
US
Hello, I'm new at coding, but in less than 3 weeks I converted a QuickBasic program to Visual Basic 5. So I guess I have the hang of it.

Question: Is there a way to run a VB program, then have a command in the program that tells it to execute a completely different program, and then use the results from the completely different program in calculating the final results in the VB program?

This "completely different" program is written in Fortran. I've a feeling that I can only accomplish this by converting the Fortran program to VB, which is unfortunate because I don't know Fortran and I don't how I could nor do I think I'm allowed to alter the Fortran program (legally).

Thanks.
pds
 
Code:
'==== bas module - declarations section ========
Option Explicit

Private Declare Function OpenProcess Lib "kernel32" _
       (ByVal dwDesiredAccess As Long, _
        ByVal bInheritHandle As Long, _
        ByVal dwProcessId As Long) As Long
Private Declare Function WaitForInputIdle Lib "user32" _
       (ByVal hProcess As Long, +
        ByVal dwMilliseconds As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
        (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
         (ByVal hObject As Long) As Long

Private Const INFINITE = &HFFFF
Private Const SYNCHRONIZE = &H100000

'==== bas modue - code section ====
Public Sub ShellAndWait(sAppPath As String, Optional _
                        iWindowStyle As VbAppWinStyle = vbMinimizedFocus, _
    Optional  lmsTimeOut As Long = INFINITE)
    'Optional argument lmsTimeOut specifies milliseconds to wait.
   'Wait forever if omitted (default).
    Dim lPid As Long, hProc As Long, lTimeOut As Long

    lPid = Shell(sAppPath, iWindowStyle)
    hProc = OpenProcess(SYNCHRONIZE, 0&, lPid)
    If hProc <> 0& Then
        WaitForInputIdle hProc, INFINITE
        WaitForSingleObject hProc, lmsTimeOut
        CloseHandle hProc
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top