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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| Option Explicit
Const ForReading = 1
Dim Fich, ReadAll, objFSO, Ret
Dim intNumberLines, intSubNumber, intProgressLines, intSubLines, intPercent
Dim strSubName, strEndSub, strNextLine, strReadAll
Const ScriptName = "findsub.vbs" ' Mettre ici le nom du fichier à traiter
' *****************************************************************************
Private Sub ClcLines()
strSubName = ""
strEndSub = ""
intSubLines = 0
intProgressLines = 0
intSubNumber = 0
intNumberLines = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ReadAll = objFSO.OpenTextFile(ScriptName,ForReading)
strReadAll = ReadAll.ReadAll
intNumberLines = ReadAll.Line ' au lieu de : {Split(strReadAll,vbCrLf)}
Set Fich = objFSO.OpenTextFile(ScriptName,ForReading)
Do
strNextLine = Fich.ReadLine
If MotEntier (strNextLine, "Sub") Then
intSubLines = intSubLines + 1
intProgressLines = intProgressLines + 1
intSubNumber = intSubNumber + 1
strEndSub = "End Sub"
strSubName = strNextLine
Ret = Ret & Cstr(intSubNumber) & "> " & strSubName
Do
strNextLine = Fich.ReadLine
intSubLines = intSubLines + 1
intProgressLines = intProgressLines + 1
Loop Until MotEntier (strNextLine, strEndSub)
Ret = Ret & "; " & intSubLines & " Lines; " & FormatNumber((intProgressLines/intNumberLines) * 100, 2) & "%" & vbCrLf
intSubLines = 0
ElseIf MotEntier (strNextLine, "Function") Then
intSubLines = intSubLines + 1
intProgressLines = intProgressLines + 1
intSubNumber = intSubNumber + 1
strEndSub = "End Function"
strSubName = strNextLine
Ret = Ret & Cstr(intSubNumber) & "> " & strSubName
Do
strNextLine = Fich.ReadLine
intSubLines = intSubLines + 1
intProgressLines = intProgressLines + 1
Loop Until MotEntier (strNextLine, strEndSub)
Ret = Ret & "; " & intSubLines & " Lines; " & FormatNumber((intProgressLines/intNumberLines) * 100, 2) & "%" & vbCrLf
intSubLines = 0
End If
Loop Until Cstr(intSubLines) = Cstr(intNumberLines) Or Fich.AtEndOfStream
Set Fich = Nothing
Set objFSO = Nothing
End Sub
' *****************************************************************************
Private Function MotEntier (strNextLine, strSearch)
If Len(strNextLine) = 0 Then
MotEntier = False
Exit Function
Else
strNextLine = LCase(LTrim(Replace(strNextLine,VbTab,"")))
strSearch = LCase(strSearch)
MotEntier = (Mid(strNextLine,1 , Len(strSearch)+1) <= strSearch & " ") And (Mid(strNextLine, 1, Len(strSearch)) = strSearch)
End If
End Function
' *****************************************************************************
'Appel de la Procédure
ClcLines()
intPercent = FormatNumber((intProgressLines/intNumberLines) * 100, 2)
Sub A(x,y)
' 1***
' 2***
' 3***
' 4***
' 5***
' 6***
End Sub
Function B(g,h)
' 1***
' 2***
' 3***
End Function
Sub C(e,f)
' 1***
' 2***
' 3***
' 4***
' 5***
' 6***
' 7***
' 8***
End Sub
MsgBox Ret & vbCrLf & vbCrLf & "- Nombre de lignes du Script >> " & intNumberLines & " Lignes" _
& vbCrLf & "- Pourcentage total des Sub/Function du Script >> " & Cstr(intPercent) & "%" |