tags:

views:

176

answers:

4

Is it possible to determine which property of an ActiveX control is the default property? For example, what is the default property of the VB6 control CommandButton and how would I found out any other controls default!

/EDIT: Without having source to the object itself

+1  A: 

I don't use VB, but here it goes.

I found Using the Value of a Control, but it's not a programmatic solution. If you have access to the code, look for

Attribute Value.VB_UserMemId = 0

using Notepad.

eed3si9n
A: 

you have access to the code, look for

Unfortunetly I don't have access to the code for most of the controls. However the link is useful for the Microsoft Controls, but I still would like a way to know for other controls.

DAC
+1  A: 

It depends on when you want to determine this. You could print the "value" of, say, a label control (which has no "value" property) to the debugger like:

debug.print "Value for cmdTest is ["+format(cmdTest)+"]"

Which will give you something like:

Value for cmdTest is [False]

As it turns out, the default value for a command button is it's state (pressed or not), so if you put the code example above in the click event for the control, you will see "True", if you execute it somewhere else, you'll see "False".

For other results, this method will at least show you the sort of property you're looking for. You could use:

debug.print "cmdTest's value is of type ["+TypeName(oObject) +"]"

which tell you the actual type, namely:

cmdTest's value is of type [Boolean]

You could use various methods to narrow things down, such as setting the value and seeing what happens.

John T
A: 

Use OLE/Com Object Viewer, which is distributed with Microsoft Visual Studio.

Go to type libraries and find the library the control is housed in, for example CommandButton is stored in Microsoft Forms 2.0 Object Library. Right click the library and select view. Find the coclass representing the control and select it:

alt text

As can be seen, the default interface for CommandButton is ICommandButton, when you inspect ICommandButton look for a property that has a dispid of 0. The IDL for the dispid 0 property of CommandButton is:

[id(00000000), propput, bindable, displaybind, hidden, helpcontext(0x001e8d04)]
void Value([in] VARIANT_BOOL rhs);
[id(00000000), propget, bindable, displaybind, hidden, helpcontext(0x001e8d04)]
VARIANT_BOOL Value();

Showing you the default property.

DAC