| |
ginolard
Posts: 1023
Score: 21
Joined: 8/10/2005
Status: offline
|
If you're anything like me you often don't bother setting your created object to Nothing when you no longer need them. Some people say you should, some (including Microsoft!) say you don't need to. Well, I figured I wouldn't give myself any excuse not to so knocked up a little script that will read any VBS file and generate Set object = Nothing statements for any objects that script creates. You can then just copy and paste them at the end of said script. Set objFSO = CreateObject("Scripting.FileSystemObject") Set objDict = CreateObject("Scripting.Dictionary") Const ForReading = 1 strFile="C:\temp\test3.vbs" InputFile=objFSO.OpenTextFile(strFile,ForReading).ReadAll ArrayFile=Split(InputFile,VbCrLf) For i = 0 To UBound(ArrayFile) If Instr(ArrayFile(i),"CreateObject" ) Then strSet=Mid(ArrayFile(i),InStr(ArrayFile(i),"Set"),InStr(ArrayFile(i),"=")) If Not objDict.Exists(strSet) Then objDict.Add strSet,strSet End If End If Next strSetArray=objDict.Keys For j = 1 To Ubound(strSetArray) WScript.Echo Replace(strSetArray(j),"="," = Nothing") Next
|
|