Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Auto-generate Set object=Nothing statements

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,26879
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Auto-generate Set object=Nothing statements
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Auto-generate Set object=Nothing statements - 10/11/2005 11:00:43 PM   
  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
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Auto-generate Set object=Nothing statements Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts