| ' Start the indicated program and wait for it
' to finish, hiding while we wait.
Private Sub ShellAndWait(ByVal program_name As String)
Dim process_id As Long
Dim process_handle As Long
    ' Start the program.
    On Error GoTo ShellError
    process_id = Shell(program_name, vbNormalFocus)
    On Error GoTo 0
    ' Hide.
    Me.Visible = False
    DoEvents
    ' Wait for the program to finish.
    ' Get the process handle.
    process_handle = OpenProcess(SYNCHRONIZE, 0, process_id)
    If process_handle <> 0 Then
        WaitForSingleObject process_handle, INFINITE
        CloseHandle process_handle
    End If
    ' Reappear.
    Me.Visible = True
    Exit Sub
ShellError:
    MsgBox "Error running '" & program_name & _
        "'" & vbCrLf & Err.Description
End Sub
' Start the program.
Private Sub cmdRun_Click()
Const COMPILER = "C:\Program Files\Microsoft Visual " & _
    "Studio\Vb98\Vb6.exe"
Const PROJECT_NAME = "Target"
Dim project_path As String
Dim project_vbp As String
Dim project_exe As String
Dim cmd As String
    ' Get the project file name.
    project_path = App.Path
    If Right$(project_path, 1) <> "\" Then project_path = _
        project_path & "\"
    project_vbp = project_path & PROJECT_NAME & ".vbp"
    project_exe = project_path & PROJECT_NAME & ".exe"
    ' Compose the compile command.
    cmd = """" & COMPILER & """ /MAKE """ & project_vbp & _
        """"
    ' Shell this command and wait for it to finish.
    ShellAndWait cmd
    ' Execute the newly compiled program.
    cmd = """" & project_exe & """"
    ShellAndWait cmd
End Sub |