You have two different options: inspecting the object's TypeName or
checking whether the TypeOf the object Is a particular type.
Public Sub DiscerningType()
Dim list As New Collection
Dim aVariable As New MyClass
Dim anotherVariable As New MyClass
Dim yetAnotherVariable As New MyOtherClass
Dim someOtherVariable As New SomeOtherClass
Dim andYetOneMoreVariable As New MyOtherClass
list.Add aVariable
list.Add anotherVariable
list.Add yetAnotherVariable
list.Add someOtherVariable
list.Add andYetOneMoreVariable
Debug.Print "Using TypeName:"
Dim current As Variant
For Each current In list
Debug.Print TypeName(current)
Next current
Debug.Print
Debug.Print "Using TypeOf...Is:"
For Each current In list
If (TypeOf current Is MyClass) Then
Debug.Print "My Class"
ElseIf (TypeOf current Is MyOtherClass) Then
Debug.Print "My Other Class"
ElseIf (TypeOf current Is SomeOtherClass) Then
Debug.Print "Some Other Class"
Else
Debug.Print "No idea what this is"
End If
Next current
End Sub
This code produces the following output:
Using TypeName:
MyClass
MyClass
MyOtherClass
SomeOtherClass
MyOtherClass
Using TypeOf...Is:
My Class
My Class
My Other Class
Some Other Class
My Other Class
Michael J. Hunter
Microsoft
michhu-at-online-dot-microsoft-dot-com
Developing Microsoft Visio Solutions:
http://msdn.microsoft.com/library/en-us/devref/HTML/DVS_Copyright_1270.asp
Developer Resources for Microsoft Visio:
http://msdn.microsoft.com/library/default.asp?url=/nhp/Default.asp?contentid=28000456
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm