To Understand it, see the example given below
For i = 1 To 10
Dim c As New Collection 'executed only once in loop
c.Add i
Next
MsgBox c.Count 'display 10
For i = 1 To 10
Dim d As Collection
Set d = New Collection 'executed every time it encountered in loop
d.Add i
Next
MsgBox d.Count 'display 1
The output of first msgbox is 10 and output of second msgbox is 1. This is due to 'dim' command is executed only once even within a loop, while 'set' command is executed each time it encountered in loop.
No comments:
Post a Comment