Basically I have a program that is sort of a manager or master program that reads in data from a live excel sheet and intiates certain subroutines by watching hotfolderd and comparing the file's contents to the info in the excel sheet. Anyway, those details are not that important, the main point is that my program releases control to other programs throughout the different subroutines. What I would like to do, is assign a hotkey - say CTRL + Q for example -, that would ideally break the subroutine, but even killing the whole program would be acceptable. My program releases control by using process handles to wait for the other programs to finsih before it continues. I have to do this because it is important that the programs are run in a particular order and do not overlap. The reason for this 'esacpe' key, is that if someone drops a file in the hotfolder, or makes an error on the spreadsheet, I would like to have the ability to stop the program instead of having it go through all the motions(some of the longest of subroutines call 30+ programs and can take well over an hour to run - you can see why a halt key would be benefitial). The way I do process handles is below:
*Begin Code*
General Declare
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const INFINITE = &HFFFFFFFF
Private Sub ProcessHandle(Process_ID As String)
Dim Process_Handle
On Error GoTo 0
Process_Handle = OpenProcess(SYNCHRONIZE, 0, Process_ID)
If Process_Handle <> 0 Then
Call WaitForSingleObject(Process_Handle, INFINITE)
Call CloseHandle(Process_Handle)
End If
End Sub
*End Code*
One of the steps is to grab a database and use a mail software to CASS certify and Pre-sort the address. For the CASS certification, this is how I am using the handle.
ProcessHandle (Shell("\\Franklin2003\DP\bcc\mm2010\MAILMAN.EXE -u " & Chr(34) & JobListArray(z).LocalUser & Chr(34) & " -j Cass_Certify" & JobListArray(z).LocalUser & ".mjb", vbNormalFocus))
Don't pay too much attention to the details in that, basically it works by ProcessHandle(Process) and my programs pauses until the executing program completes its task and closes. My program then resumes. I know how to do basic hotkey setups, but those only work if the code is not currently running a subroutine. For example, I can set CTRL-X to unload my form. This works while it is stationary, but if it is in a subroutine the hotkey fails.
I really don't care about it stopping the currently running process that the handle is waiting on(I can ctrl+alt+del that after my main programs exits). Just being able to hit a hotkey and then when the currently running program finishes it causes my code to either break the subroutine(as there is usually a long list of other programs to call before the sub is done), or halt and unload itself completely. I can't figure out a way because as long as the loop is waiting for control to be restored it ignores any keyboard strokes. So I assume I would need to add something to the process handle subroutine itself that would cause the halt.
I've done a lot of research, but can't come up with a solution. If any of you can think of something you would be doing me a great favor. Thanks for reading my novel
-Tril
Enter your message below
Sign in or Join us (it's free).