It seems to me that you have the opportunity for a collection of terminals in the wrong place. Ask LoadTerminals to return the collection of created terminals: -
Option Explicit
Sub BuildTerminalSummary()
Dim terminals As Collection
Dim terminal As clsTerminal
Set terminals = LoadTerminals
For Each terminal in terminals
...Do work here
Next terminal
End Sub
Private Function LoadTerminals() As Collection
Dim terminals As Collection : Set terminals = New Collection
Do
Set terminal = New clsTerminal
''
terminals.Add terminal, key
Loop Until endCondition
Set LoadTerminals = terminals
End Function
As long as you have variables, there is no need to especially βdeleteβ them (which, I think, you mean assigning a Nothingvariable containing a link to them.
source
share