K & K Consulting    K & K Consulting

K&K Home VB Guru Home Search VB Site VB Code VB Tips VB Tutorials VB Questions

K&K Home
Up
VB Home

 

Make Your VB App Wait Tip

 

Derek E. Brown sends in this tip that should be very useful in a number of situations that can arise. The tip involves making a VB app wait for the completion of some other process outside VB. While Derek has a specific purpose in mind for this one, it should be fairly easy to modify for a number of different situations.

I found this to be an extremely useful piece of code for running an application from within VB and having the VB app wait until the outside process is complete. I have a program that has to wait until an uploaded zip file is unzipped before continued processing can take place. The code below involves a few API's, and though it's rather long and involved, I have yet to get an error using it.

'**************************************
'Windows API/Global Declarations for :Un'zipper
'**************************************
Private Const ZIPSIG = &H4034B50
Private Const ziputil = "c:\Program Files\PKUnzip\Pkzip25.exe"
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFFFFFF
'API's to monitor the status of Pkzip

Private Declare Function OpenProcess Lib "kernel32" (ByVal DesiredAccess As Long, _ ByVal bInheritHandle As Long, ByVal ProcessId As Long) As Long

Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, _ ByVal Milliseconds As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long 

Private Type ZFHeader 
Signature As Long 
End Type

***********************************
Private Sub sb_WaitForTemination(RetVl As Integer)

On Error Goto ErrorHandler:

Dim phnd&

phnd = OpenProcess(SYNCHRONIZE, 0, RetVl)

If phnd <> 0 Then
  Call WaitForSingleObject(phnd, INFINITE)
  Call CloseHandle(phnd)
End If

Exit Sub

ErrorHandler:
  Err.Source = "sb_WaitForTermination in class Unzip in UnZipper"
  'Do Error Stuff Here
  Resume Next
End Sub

Send mail to WebMaster with questions or comments about this web site.
This website is best viewed with a screen resolution of 800*600 or better.
This website is optimized for Microsoft Internet Explorer 6.x
K&K Consulting, Proud to be a Microsoft Business Partner.
Last modified: January 31, 2002