9f4136a119aa096b3b4faf1c33a7e08e

This horrible code I inherited uses a GOTO. Anyone care to fix it?

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 !

22e33503870d8e20493c4dd6b2f9767f

rikkus

September 25, 2008, September 25, 2008 16:56, permalink

No rating. Login to rate!

This kind of error handling is idiomatic in VB.

9f4136a119aa096b3b4faf1c33a7e08e

hcase

September 25, 2008, September 25, 2008 23:33, permalink

No rating. Login to rate!

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
503dc458e66746c5ac681e7057d209dd

McDole

September 26, 2008, September 26, 2008 16:24, permalink

No rating. Login to rate!

*Removed*

Your refactoring





Format Copy from initial code

or Cancel