Object Property

What do you do when you've created a method or property for a control but used the same name as one that VB gives it anyway?

After all we all know that: "Visual Basic supplies some or all of a standard set of properties and methods to controls in a Visual Basic project. It is possible for a control or ActiveX component (such as Microsoft Excel or Microsoft Word) to define a property or method which has the same name as one of these standard properties or methods. When this occurs, Visual Basic automatically uses the property or method it supplies instead of the one with the same name defined in the control." MSDN Library (on-line)

Thankfully the object property returns a reference to a method or property of a control which has the same name as a method or property that VB extends to the control automatically. So you can now reference the controls' "custom" methods and properties through the Object property.

This works because "The Object property returns the object which is the basis for the control without the properties or methods automatically extended to the control by Visual Basic." MSDN Library (on-line)

So effectively the Object property means that you can bypass the VB-supplied named parts and use your identically (and incorrectly) named method, property or whatever that you defined for your control.

This basically boils down to a work around for name space issues.


Syntax

object.Object[.property | .method]

The Object property syntax has these parts:

Object: An object expression that evaluates to an object in the Applies To list.
Property: Property of the control that is identical to the name of a Visual Basic-supplied property.
Method: Method of the control that is identical to the name of a Visual Basic-supplied method.

--MSDN Library (on-line)


VB automatically extends some or all of the following properties, methods, and events to controls in a Visual Basic project:

Properties

Align Height
Binding
Bindings
Cancel
Container
DataChanged
DataField
DataSource
Default
DragIcon
DragMode
HelpContextID
Index
Left
LeftNoRun
LinkItem
LinkMode
LinkTimeout
LinkTopic
Name
NegotiateLinkItem
Object
Parent
TabIndex
TabStop
TagParent
ToolTipText
Top
TopNoRun
VisibleTabStop
WhatsThisHelpID
Width

Methods

Drag
HowWhatsThis
LinkExecute
LinkPoke
LinkRequest
LinkSend
Move
Refresh
SetFocus
Zorder

Events

GotFocus
LinkClose
LinkError
LinkNotify
LinkOpen
LostFocus

Lastly the MSDN has this to say:

"If you use a property or method of a control and don't get the behavior you expect, check to see if the property or method has the same name as one of those shown in the preceding list. If the names match, check the documentation provided with the control to see if the behavior matches the Visual Basic-supplied property or method. If the behaviors aren't identical, you may need to use the Object property to access the feature of the control that you want." MSDN Library (on-line)


References:

  •  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbproobjectextd.asp
  • All those years of experience...
  • All those "useless" notes I made when studying the subject.
You may allso like to read Textbox but then again it might be time for something funny

This WU was resqued from a file in tempory internet files after a random corruption distroyed the original node.

Some have pointed out that bits of this write-up suck a little... I am not sure how I will fix this yet

Log in or register to write something here or to contact authors.