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
| Option Explicit
Const ForReading = 1
Dim Fich, intSublines, intPercent, strNextLine
Dim objFSO, strReadAll, strReadSub, arrline
Const ScriptName = "FindSub.vbs" ' Mettre ici le nom du fichier à traiter
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set Fich = objFSO.OpenTextFile(ScriptName,ForReading)
strReadAll = Fich.ReadAll
' nombre total de ligne du fichier y compris les sauts de lignes
arrline = Fich.Line ' au lieu de : {Split(strReadAll,vbCrLf)}
intSublines = 0
Set strReadSub = objFSO.OpenTextFile(ScriptName,ForReading)
Do While Not strReadSub.AtEndOfStream
strNextLine = strReadSub.Readline
If InStr(1, strNextLine, "Sub") > 0 And InStr(1, strNextLine, "End Sub") = 0 Then
intSublines = intSublines + 1 ' incrémente le nbr de ligne
End If
If InStr(1, strNextLine, "End Sub") > 0 Then
intSublines = intSublines ' Nombre total de ligne y compris (Sub) et (End Sub)
Exit Do
End If
Loop
intPercent = FormatNumber((intSublines / arrline) * 100,2) ' 2 chiffres après la virgule
MsgBox "Nb Lignes de la Sub: " & intSublines & vbCrLf & "Nb Lignes du Script: " & arrline & vbCrLf & "Pourcentage: " & intPercent & "%", vbInformation,"Fonction"
' ********************
Sub A
' 1***
' 2***
' 3***
' 4***
' 5***
End Sub
Set objFSO = Nothing |
Partager