Re: msgbox syntax question

Tech-Archive recommends: Fix windows errors by optimizing your registry



Thank you very much Ken, I do remember it now...also, thanks for the
example.

Regards.

David Clifford

"Ken Halter" <Ken_Halter@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23QgxqXPOHHA.3916@xxxxxxxxxxxxxxxxxxxxxxx
"David" <myself@xxxxxxxxxxx> wrote in message
news:OitqdJPOHHA.4100@xxxxxxxxxxxxxxxxxxxxxxx
Hello all.

I once read, I think in this forum, that the msgbox syntax should be:

msgbox "Your message", vbInformation Or vbYesNo

rather than:

msgbox "Your message", vbInformation + vbYesNo

I can't remember why one uses OR instead of +, can someone please
refresh
my
memory?

Thank you

Regards

David Clifford


It's mostly a matter of style, as far as a messagebox goes. vbInformation,
vbYesNo and similar are bitmasks. In most cases, + will work fine, but if
you accidentally add the same flag twice (say, you're passing flags around
to different methods before using them), there can be "issues"... Using Or
to set bitmasks eliminates the possiblity of setting the wrong flags due
to
recursion, etc....
'==============
Private Sub Command1_Click()
Dim eBitMask As VbMsgBoxStyle

eBitMask = vbCritical

'Use Plus - Notice the buttons are not set = abort/retry/ignore
eBitMask = eBitMask + vbAbortRetryIgnore
eBitMask = eBitMask + vbAbortRetryIgnore
MsgBox "Test", eBitMask

'Reset mask
eBitMask = vbCritical

'Use Or - Notice the buttons are set = abort/retry/ignore
eBitMask = eBitMask Or vbAbortRetryIgnore
eBitMask = eBitMask Or vbAbortRetryIgnore
MsgBox "Test", eBitMask

End Sub
'==============

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
In Loving Memory - http://www.vbsight.com/Remembrance.htm




.


Quantcast