Manage Learn to apply best practices and optimize your operations.

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

Dig Deeper on Domino Resources - Part 2

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...