In VB6, is there a way to block or delay an event ? I want to finish my transaction process before the program go to other event handler.
Printable View
In VB6, is there a way to block or delay an event ? I want to finish my transaction process before the program go to other event handler.
Sonnyzhang,
This might help. Not sure if it's exactly what you're looking for.
In this example the cmdCreateFile.Enabled will not be reset until you are done with Notepad.Code:'Declaration of Synchronizing Windows applications
Public Const PROCESS_ALL_ACCESS = 2035711 '(&H1F0FFF)
Public Const INFINITE = -1 '(&HFFFFFFFF)
Public Const WAIT_FAILED = -1 '(&HFFFFFFFF)
Public Const STILL_ACTIVE = 259 '(&H103)
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Function WaitOnProgram(ByVal idProg As Long, Optional ByVal WaitDead As Boolean) As Long
Dim cRead As Long, iExit As Long, hProg As Long
' Get process handle
hProg = OpenProcess(PROCESS_ALL_ACCESS, False, idProg)
If WaitDead Then
' Stop dead until process terminates
Dim iResult As Long
iResult = WaitForSingleObject(hProg, INFINITE)
If iResult = WAIT_FAILED Then 'ErrRaise Err.LastDllError
MsgBox "Error during Shell command"
End If
' Get the return value
GetExitCodeProcess hProg, iExit
Else
' Get the return value
GetExitCodeProcess hProg, iExit
' Wait, but allow painting and other processing
Do While iExit = STILL_ACTIVE
DoEvents
GetExitCodeProcess hProg, iExit
Loop
End If
' CloseHandle hProg
WaitOnProgram = iExit
End Function
Public Sub RunSyncro(appname As String)
Dim idProg As Double
Dim iExit As Long
Dim temp As String
temp = appname ' & commandLine
idProg = Shell(temp, 1)
iExit = WaitOnProgram(idProg)
If iExit <> 0 Then
MsgBox App.Title & " could not find " & """" & appname & """", 48
End If
End Sub
' How to use
cmdCreateFile.Enabled = False
RunSyncro ("Notepad.exe C:\Test\TestFile.txt")
cmdCreateFile.Enabled = True
Hi Confucius,
Your code gives me some hints. But it is not quite fit my situation. I think your example will hung up the whole VB process until the child process complete. What I am looking for is blocking or delaying other event handler in the same VB project until one method is completed.
What about using a timer with a boolean?