code_junkie

VB6 Runtime Type Retrival

Nov 10th, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. If Typeof(foobar) = "CommandButton" Then ...
  2.  
  3. Dim y As Object
  4.  
  5. Set y = CreateObject("SomeType")
  6.  
  7. Debug.Print( <The type name of> y)
  8.  
  9. If TypeName(foobar) = "CommandButton" Then
  10. DoSomething
  11. End If
  12.  
  13. Private Sub Command1_Click()
  14. Dim oObject As Object
  15. Set oObject = CreateObject("Scripting.FileSystemObject")
  16. Debug.Print "Object Type: " & TypeName(oObject)
  17. End Sub
  18.  
  19. Typename()
  20.  
  21. Private Sub cmdCommand1_Click()
  22. Dim a As Variant
  23. Dim b As Variant
  24. Dim c As Object
  25. Dim d As Object
  26. Dim e As Boolean
  27.  
  28. a = ""
  29. b = 3
  30. Set c = Me.cmdCommand1
  31. Set d = CreateObject("Project1.Class1")
  32. e = False
  33.  
  34. Debug.Print TypeName(a)
  35. Debug.Print TypeName(b)
  36. Debug.Print TypeName(c)
  37. Debug.Print TypeName(d)
  38. Debug.Print TypeName(e)
  39. End Sub
  40.  
  41. String
  42. Integer
  43. CommandButton
  44. Class1
  45. Boolean
Add Comment
Please, Sign In to add comment