How to check type of object in VB 6 - Is there any method other than 'TypeName' because its not feasible to check it witrh 'TypeName' I am expecting something like QuichWatch window.
views:
64answers:
3
+3
A:
For object variables:
If TypeOf VarName Is TypeName Then
''# ...
End If
For example:
Dim fso As New Scripting.FileSystemObject
If TypeOf fso Is Scripting.FileSystemObject Then
Debug.Print "Yay!"
End If
Tomalak
2010-09-10 12:50:40
+1
A:
Just to add to @Tomalak's answer... If the object variable has not been instantiated then testing with TypeOf will cause a run time error. Also note the class may implement interfaces e.g.
Dim fs As Scripting.FileSystemObject
On Error Goto Err_Handler
If TypeOf fs Is Scripting.FileSystemObject Then
Debug.Print "[Won't get here]"
End If
Err_Handler:
If Err.Number <> 0 Then
Debug.Print "Oops, error when fs Is Nothing"
End If
On Error Resume Next
Set fs = New Scripting.FileSystemObject
If TypeOf fs Is Scripting.FileSystemObject Then
Debug.Print "Is a FileSystemObject"
End If
If TypeOf fs Is IFileSystem Then
Debug.Print "Implements IFileSystem "
End If
onedaywhen
2010-09-10 13:32:57
A:
try this one.
dim obj as object
for each obj in me
debug.print TypeName(obj)
next
dave
2010-09-15 08:23:15
Thanks, but do check type of object we have to modify existing code is there any method like moving cursor orer it or like quick watch where I can see its type
2010-09-21 10:22:44
Thanks for providing answeers.... :)
2010-10-04 15:15:24