The code for this property is very simple. It simply passes the
UseHelp
Button
value back and forth. Notice that the comment for the
Let
method
includes a reference to the
vbMsgBoxHelpButton
style. (Whenever you con-
vert a function or other real-world entity into an object, try to preserve the
original information in the comments that you write.) This comment helps
you remember that this property replaces the
vbMsgBoxHelpButton
style.
Property naming considerations
You normally want to use the same names for properties in your object that
other programmers use for their objects. This technique makes it easier for
you to remember the purpose of a property. However, you also want to avoid
confusion. If a property doesn’t provide precisely the same functionality, it’s
better to use a different name. For example, the
MsgBox
function provides the
vbMsgBoxRight
style to allow flush-right text alignment. You might think that
you should use the
TextAlign
property found in other objects, such as the
Label
control. However, the
TextAlign
property allows left, center, and
right text alignment, so using this name for the example could prove confusing
because the
MsgBox
function doesn’t allow center alignment. The example
uses a
Boolean
value and a different name for the property, as shown here:
Public Static Property Let RightAlignText(Value As
Boolean)
‘ Should the example use the vbMsgBoxRight style?
UseRightAlignment = Value
End Property
Public Static Property Get RightAlignText() As Boolean
‘ Return the vbMsgBoxRight value.
RightAlignText = UseRightAlignment
End Property
Notice that the property name is very specific. The name makes it clear that
left alignment is the default and that you can only choose right alignment as
an option.
The
MsgBox Context
argument does precisely match the
HelpContextID
property used by many existing objects, so the example does use that name
for the property. I ran into a problem with the
MsgBox Prompt
and
Title
arguments. Theoretically, both arguments should appear as part of the
Caption
property. When you set the
Caption
property of a
UserForm
,
you set the title bar text. Likewise, the
Caption
property sets the text that
appears in a
Label
control. The example uses the
Caption
property for
the
Prompt
argument and uses a
Title
property for the
Title
argument.
Because you use the
Prompt
argument more often, setting it equal to the
Caption
property makes sense.
190
Do'stlaringiz bilan baham: