Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Set objEct = Nothing
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



Report this thread to moderator Post Follow-up to this message
Old Post
Andy
10-29-04 08:55 PM


Re: Set objEct = Nothing
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:

>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
>


Report this thread to moderator Post Follow-up to this message
Old Post
alpine
10-29-04 08:55 PM


Re: Set objEct = Nothing
"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"


Report this thread to moderator Post Follow-up to this message
Old Post
Bob Butler
10-29-04 08:55 PM


Re: Set objEct = Nothing
"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



Report this thread to moderator Post Follow-up to this message
Old Post
YYZ
10-29-04 08:55 PM


Re: Set objEct = Nothing
You 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
>
>
>.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Andy
10-29-04 08:55 PM


Re: Set objEct = Nothing
I 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:
> 
>
>.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Andy
10-29-04 08:55 PM


Re: Set objEct = Nothing
You 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"
>
>.
>

Report this thread to moderator Post Follow-up to this message
Old Post
Andy
10-29-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Visual Basic archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:09 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.