1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Private Function fIsAppRunning() As Boolean 'Looks to see if Lotus Notes is open Dim lngH As Integer Dim lngX, lngTmp As Integer Const WM_USER As Short = 1024 On Error GoTo fIsAppRunning_Err fIsAppRunning = False lngH = FindWindow("NOTES", vbNullString) If lngH <> 0 Then SendMessage(lngH, WM_USER + 18, 0, 0) lngX = IsIconic(lngH) If lngX <> 0 Then lngTmp = ShowWindow(lngH, 1) End If lngTmp = SetForegroundWindow(lngH) fIsAppRunning = True End If fIsAppRunning_Exit: Exit Function fIsAppRunning_Err: fIsAppRunning = False Resume fIsAppRunning_Exit End Function
Refactorings
No refactoring yet !
rikkus
September 25, 2008, September 25, 2008 16:56, permalink
This kind of error handling is idiomatic in VB.
hcase
September 25, 2008, September 25, 2008 23:33, permalink
My own refactoring since noone seems interested.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Private Function IsAppRunning() As Boolean 'Looks to see if Lotus Notes is open Dim lngH As Integer Dim lngX, lngTmp As Integer Const WM_USER As Short = 1024 IsAppRunning = False Try lngH = FindWindow("NOTES", vbNullString) If lngH <> 0 Then SendMessage(lngH, WM_USER + 18, 0, 0) lngX = IsIconic(lngH) If lngX <> 0 Then lngTmp = ShowWindow(lngH, 1) End If lngTmp = SetForegroundWindow(lngH) IsAppRunning = True End If Catch x As Error IsAppRunning = False End Try End Function
This horrible code I inherited uses a GOTO. Anyone care to fix it?