Reputation: 427
There are three only ways, which are discussed on the Internet and on this forum in particular
How to check type of object in VB 6 - Is there any method other than 'TypeName'
How to check type of Object in VB 6 ? - I do not want to use 'TypeOf' method
How to check type of object in VB 6 - Is there any method other than 'TypeName'
Namely:
- the string method TypeName
- the clumsy TypeOf
- by name of control, defined in a specific notation
Am I right, that there are no built-in tools to get a normal numeric constant, like the MsoControlType
?
.
Upvotes: 1
Views: 6102
Reputation: 71217
Am I right, that there are no built-in tools to get a normal numeric constant, like the MsoControlType?
Yes, that is correct. Unless you implement your own, using the techniques you've listed.
Well, excluding VarType
, which will return vbObject
given any object reference.
What you're referring to as a "normal numeric constant" has strictly nothing to do with a control's type - these MsoControlType
constants are just Enum
values that the CommandBar
API uses to determine the type of the control to create when you ask to create one.
MsoControlType.msoControlButton
is not a type of control, it's a constant with a value of 1. Nothing more, nothing less - the type of a control is a class, not a numeric constant:
?TypeName(Application.VBE.CommandBars(1).Controls(1))
CommandBarPopup
CommandBarPopup
is the class (and thus the type of the control), not msoControlPopup
, and not 10
:
A type is what you give to TypeOf [variable] Is [*type*]
, or Dim [variable] As [*type*]
: it's an identifier that refers to a class/interface (in the case of an object, of course - a type could also be one of the primitives, e.g. Integer
or Boolean
). And given the weakness of reflection capabilities in VB6/VBA for lack of a .net-like type system where a type itself is an abstraction that can be worked with, a custom Enum
type and a function taking an object, featuring a Select Case
block with TypeOf
checks, is your best bet for that function to return a normal numeric constant that represents the type of the provided object.
Upvotes: 9