I have a class called assetTransfer
.
If I have a loop and I create a new instance with the same name, what happens with the "old" one?
For i = 1 to 10
Dim assetTransfer as New assetTransfer
next
Do I lose the previous instance?
I have a class called assetTransfer
.
If I have a loop and I create a new instance with the same name, what happens with the "old" one?
For i = 1 to 10
Dim assetTransfer as New assetTransfer
next
Do I lose the previous instance?
In your case specifically assetTransfer
will never be instantiated, since it is never called. MS Docs
The dim foo as new bar
statement should be avoided in most cases, instead use separate declaration and instantiation like: dim foo as bar
and set foo = new bar
Reason: What's the difference between Dim As New vs Dim / Set
A way to solve this would look like this.
At the end you have 10 instances of assetTransfer in your Collection
dim aCollection as Collection
set aCollection = new Collection
Dim assetTransferInstance as assetTransfer
For i = 1 to 10
set assetTransferInstance = new assetTransfer
'do something with assetTransfer
aCollection.Add assetTransferInstance
next i
debug.print aCollection.Count '10