Code Comments
Programming Forum and web based access to our favorite programming groups.I have these few lines of code in my Sub Main that I am thinking of getting eliminated because the very last one gives me an error (who knows why?) Do I RELLY NEED to set them to Nothing? I know I should, but ... I don't like to get an error Option Explicit Public Cn As ADODB.Connection Public recProcTable As ADODB.Recordset Dim m_objFSO As Scripting.FileSystemObject Dim m_objFSO1 As Scripting.FileSystemObject Dim m_objFSO2 As Scripting.FileSystemObject Sub Main() 'Some code with no errors here Set Cn = Nothing Set recProcTable = Nothing Set m_objFSO = Nothing Set m_objFSO1 = Nothing Set m_objFSO2 = Nothing <== this line gives me Err.Number = 0 End Sub I do have an error handler in there and I *could* ignore the Err.Number = 0 Would that be better than setting them to Nothing? --- Andy
Post Follow-up to this messageThe best thing would be to not use the FSO in the first place! ;-) HTH, Bryan ________________________________________ ____________________ New Vision Software "When the going gets weird," Bryan Stafford "the weird turn pro." alpine_don'tsendspam@mvps.org Hunter S. Thompson - Microsoft MVP-Visual Basic Fear and Loathing in LasVegas On Fri, 29 Oct 2004 07:39:26 -0700, "Andy" <Andrzej7@hotmail.com> wrote: >I have these few lines of code in my Sub Main that I am >thinking of getting eliminated because the very last one >gives me an error (who knows why?) > >Do I RELLY NEED to set them to Nothing? >I know I should, but ... I don't like to get an error > >Option Explicit > >Public Cn As ADODB.Connection >Public recProcTable As ADODB.Recordset >Dim m_objFSO As Scripting.FileSystemObject >Dim m_objFSO1 As Scripting.FileSystemObject >Dim m_objFSO2 As Scripting.FileSystemObject > >Sub Main() > > 'Some code with no errors here > > Set Cn = Nothing > Set recProcTable = Nothing > Set m_objFSO = Nothing > Set m_objFSO1 = Nothing > Set m_objFSO2 = Nothing <== this line gives me >Err.Number = 0 > >End Sub > >I do have an error handler in there and I *could* ignore >the Err.Number = 0 >Would that be better than setting them to Nothing? > >--- Andy >
Post Follow-up to this message"Andy" <Andrzej7@hotmail.com> wrote in message news:201501c4bdc5$174102c0$a601280a@phx.gbl > I have these few lines of code in my Sub Main that I am > thinking of getting eliminated because the very last one > gives me an error (who knows why?) > > Do I RELLY NEED to set them to Nothing? > I know I should, but ... I don't like to get an error > > Option Explicit > > Public Cn As ADODB.Connection > Public recProcTable As ADODB.Recordset > Dim m_objFSO As Scripting.FileSystemObject > Dim m_objFSO1 As Scripting.FileSystemObject > Dim m_objFSO2 As Scripting.FileSystemObject > > Sub Main() > > 'Some code with no errors here > > Set Cn = Nothing > Set recProcTable = Nothing > Set m_objFSO = Nothing > Set m_objFSO1 = Nothing > Set m_objFSO2 = Nothing <== this line gives me > Err.Number = 0 > > End Sub > > I do have an error handler in there and I *could* ignore > the Err.Number = 0 > Would that be better than setting them to Nothing? Err.Number 0 means no error happened... that's usually cause by doing something like this: On Error Goto eh Set m_objFSO2 = Nothing eh: Msgbox "Error " & err.number You need to add an "Exit Sub" before the error handler otherwise VB execution falls right through into it. A bigger issue is the use of the FSO from a VB application. Except for quick & dirty apps there is always a better way to access files and folders from VB than the use of the scripting objects. -- Reply to the group so all can participate VB.Net... just say "No"
Post Follow-up to this message"Andy" <Andrzej7@hotmail.com> wrote in message news:201501c4bdc5$174102c0$a601280a@phx.gbl... > I have these few lines of code in my Sub Main that I am > thinking of getting eliminated because the very last one > gives me an error (who knows why?) > > Do I RELLY NEED to set them to Nothing? > I know I should, but ... I don't like to get an error > > Option Explicit > > Public Cn As ADODB.Connection > Public recProcTable As ADODB.Recordset > Dim m_objFSO As Scripting.FileSystemObject > Dim m_objFSO1 As Scripting.FileSystemObject > Dim m_objFSO2 As Scripting.FileSystemObject > > Sub Main() > > 'Some code with no errors here > > Set Cn = Nothing > Set recProcTable = Nothing > Set m_objFSO = Nothing > Set m_objFSO1 = Nothing > Set m_objFSO2 = Nothing <== this line gives me > Err.Number = 0 > > End Sub Is that the real code? What is the error again? 0? Normally that's because you forgot to exit sub before an error handler. But your code doesn't show this. Normally, I'd say it doesn't matter if you set them to nothign or not, but if you are getting an error 0 when doing it, then you have something else wrong, so don't hide it, find it. Matt
Post Follow-up to this messageYou are right: Exit Sub was missing :) That's what happens when I mess with somebody else's code.... Thank you. ---- Andy >-----Original Message----- > >"Andy" <Andrzej7@hotmail.com> wrote in message >news:201501c4bdc5$174102c0$a601280a@phx.gbl... > >Is that the real code? What is the error again? 0? Normally that's >because you forgot to exit sub before an error handler. But your code >doesn't show this. Normally, I'd say it doesn't matter if you set them to >nothign or not, but if you are getting an error 0 when doing it, then you >have something else wrong, so don't hide it, find it. > >Matt > > >. >
Post Follow-up to this messageI tottaly agree, but this is somebody else's code, I just mess with it a little bit.... --- Andy BTW - Exit Sub was missing :( >-----Original Message----- >The best thing would be to not use the FSO in the first place! ;-) > >HTH, >Bryan > ________________________________________ __________________ __ >New Vision Software "When the going gets weird," >Bryan Stafford "the weird turn pro." >alpine_don'tsendspam@mvps.org Hunter S. Thompson - >Microsoft MVP-Visual Basic Fear and Loathing in LasVegas > > >On Fri, 29 Oct 2004 07:39:26 -0700, "Andy" <Andrzej7@hotmail.com> >wrote: > > >. >
Post Follow-up to this messageYou are right: Exit Sub was missing :) That's what happens when I mess with somebody else's code.... Thank you. ---- Andy >-----Original Message----- >"Andy" <Andrzej7@hotmail.com> wrote in message >news:201501c4bdc5$174102c0$a601280a@phx.gbl > >Err.Number 0 means no error happened... that's usually cause by doing >something like this: > >On Error Goto eh >Set m_objFSO2 = Nothing > >eh: >Msgbox "Error " & err.number > >You need to add an "Exit Sub" before the error handler otherwise VB >execution falls right through into it. > >A bigger issue is the use of the FSO from a VB application. Except for >quick & dirty apps there is always a better way to access files and folders >from VB than the use of the scripting objects. > >-- >Reply to the group so all can participate >VB.Net... just say "No" > >. >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.