私はそれは同じでon error goto 0
とon error goto [label]
に対処しません
(コーディングが少し迅速かつ汚いですが、動作するように思われることに注意してください)この情報を抽出するために、この(VB.NET)コードを書きましたサブルーチン:
Private Sub SearchForNoErrorHandlers(ByVal path As String)
Dim line As String, subName As String = "", inSub As Boolean = False, handlerFound As Boolean = False
For Each file As String In Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
'Debug.WriteLine(file) 'gives the full path and filename of any files found
If file.EndsWith(".bas") OrElse file.EndsWith(".cls") OrElse file.EndsWith(".frm") Then
Using sr As New StreamReader(file)
Do Until sr.EndOfStream
line = sr.ReadLine
'Debug.WriteLine(line)
If IsStartOfSub(line) AndAlso Not inSub Then
subName = line
inSub = True
handlerFound = False
ElseIf IsEndOfSub(line) AndAlso inSub Then
inSub = False
If handlerFound = False Then
Debug.WriteLine("** No handler found for file {0} in Sub: {1}", file, subName)
End If
ElseIf line.ToUpper.Contains("ON ERROR") AndAlso inSub Then
handlerFound = True
End If
Loop
End Using
End If
Next
End Sub
Private Function IsStartOfSub(ByVal line As String) As Boolean
Dim subTextPosition As Integer = line.ToUpper.IndexOf("SUB ")
Dim functionTextPosition As Integer = line.ToUpper.IndexOf("FUNCTION ")
Dim openBracket As Integer = line.IndexOf("(")
Dim closeBracket As Integer = line.IndexOf(")")
If subTextPosition >= 0 AndAlso openBracket >= 0 AndAlso closeBracket >= 0 AndAlso closeBracket > openBracket AndAlso openBracket > subTextPosition Then
Return True
ElseIf functionTextPosition >= 0 AndAlso openBracket >= 0 AndAlso closeBracket >= 0 AndAlso closeBracket > openBracket AndAlso openBracket > functionTextPosition Then
Return True
Else
Return False
End If
End Function
Private Function IsEndOfSub(ByVal line As String) As Boolean
Return (line.ToUpper.Contains("END SUB") OrElse line.ToUpper.Contains("END FUNCTION"))
End Function