LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Is it necessary to Set a Object to nothing before referencing itagain to some other object?

Hi all,

a very important question for me: suppose I am reading some objects
into a collection. Each time I create an object and add it: since I
use always the same name for the object, do I need to set the object
to Nothing before reinstancing it or not? An example follows:

(Class1)
Public InstanceName As String

(Module1)
Option Explicit

Sub AddToCollection()
Dim MyCollection As Collection
Dim Inst As Class1, x As Class1
Dim Msg As String, TheName As String

Set MyCollection = New Collection
Do
Set Inst = New Class1 ' Create a new instance of Class1.
Msg = "Please insert a new object name " & _
"or press Cancel to exit"
TheName = InputBox(Msg, "Name the Collection Items")
Inst.InstanceName = TheName ' Put name in object instance.
' If user entered name, add it to the collection.
If Inst.InstanceName < "" Then
' Add the named object to the collection.
MyCollection.Add Item:=Inst
End If
' Clear the current reference in preparation for next one.
Set Inst = Nothing
Loop Until TheName = ""

End Sub

If I omit the line

Set Inst = Nothing

the code works all the same. Is it correct to omit it? Or am I wasting
memory, and this could be dangerous in a bigger code? Thanks,

Best Regards

Sergio Rossi

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
referencing web site object Atishoo Excel Programming 3 November 20th 09 04:45 PM
Referencing two versions Object models Cory Excel Programming 4 February 9th 08 07:19 PM
Referencing Object Names with Variable jbl25[_8_] Excel Programming 1 August 26th 05 12:44 AM
Referencing worksheet CODENAME in a chart object. Bing Excel Programming 2 February 14th 05 07:08 PM
Re referencing an object rci Excel Programming 1 February 1st 04 04:49 AM


All times are GMT +1. The time now is 01:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"