Calling an External Program from a Button and Resuming LotusScript

The following routine will allow you to call another program from LotusScript, wait for that program to finish and continue running your script. The Yield example in Designer help uses an obsolete API call. To illustrate this routine, create a new form and add a hotspot button. Add the code below to your button.

Put this code in the declarations section

 Declare Function GetActiveWindow Lib "user32.dll" () As Long Type SHELLEXECUTEINFO cbSize As Long fMask As Long hwnd As Long lpVerb As String lpFile As String lpParameters As String lpDirectory As String nShow As Long hInstApp As Long lpIDList As Long lpClass As String hkeyClass As Long dwHotKey As Long hIcon As Long hProcess As Long End Type Const SEE_MASK_NOCLOSEPROCESS = &H40 Const SW_SHOWNORMAL = 1 Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteExA" (lpExecInfo As SHELLEXECUTEINFO) As Long Const SE_ERR_FNF = 2 Declare Function WaitForSingleObject Lib "kernel32.dll" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long Const INFINITE = &HFFFF Const WAIT_TIMEOUT = &H102 Sub Click(Source As Button) Dim haWnd As Long ' handle to the active window haWnd = GetActiveWindow() Dim sei As SHELLEXECUTEINFO ' structure used by the function Dim retval As Long ' return value ' Load the information needed to open C:WindowsCalc.exe into the structure. ' Size of the structure sei.cbSize = Len(sei) ' Use the optional hProcess element of the structure. sei.fMask = SEE_MASK_NOCLOSEPROCESS ' Handle to the window calling this function. sei.hwnd = haWnd ' The action to perform: open the file. sei.lpVerb = "open" ' The file to open. sei.lpFile = "C:windowscalc.exe" ' No additional parameters are needed here. sei.lpParameters = "" ' The default directory -- not really necessary in this case. sei.lpDirectory = "C:windows" ' Simply display the window. sei.nShow = SW_SHOWNORMAL ' The other elements of the structure are either not used or will be set when the function returns. retval = ShellExecuteEx(sei) If retval = 0 Then ' The function failed, so report the error. Err.LastDllError could also be used instead, if you wish. Select Case sei.hInstApp Case SE_ERR_FNF Msgbox "The application C:WindowsCalc.exe cannot be located." Case Else Msgbox "An unexpected error occured." End Select Else ' Wait for the opened process to close before continuing. Instead of waiting once for a time of INFINITE, this example repeatedly checks to see if the is still open. This allows the DoEvents function to be called, preventing our script from appearing to lock up while it waits. Do Doevents retval = WaitForSingleObject(sei.hProcess, 0) Loop While retval = WAIT_TIMEOUT Msgbox "Calculator has just closed." End If End Sub

This was first published in December 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.