Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple vb message box question

Status
Not open for further replies.

RiverGuy

Programmer
Jul 18, 2002
5,011
US
I think before I've used a vbOKCancel type message box but had the cancel button as the default button. I can't remember how I did it. Does anyone have an idea?>

Thanks
 
Try this:

MsgBox "Yes?", vbOKCancel + vbDefaultButton2

When you type in msgbox and it's prompt then intellisense shows choices for vbOKCancel etc. These can be added together as required. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Thanks for the replies! Exactly what I needed.
 
Just a small point... it's actually better to OR the options together rather than +. Ladyhawk. [idea]
** ASP/VB/Java Programmer **
 
Ladyhawk,

Why is it better to use OR for the buttons argument instead of using a +?

In MSDN, Microsoft shows the + being used for the constants in their Msgbox example and I've never had a problem with it.

Thanks!
 
1 + 5 is alot different than
1 or 5
I'm not sure what you are trying to say Ladyhawk but I'd go with the +. I suppose you could do a bitwise AND but it is easier just to add them.
 
I think Ladyhawke is getting at the fact that the various flags are actually bitmasks, and that you ought to get used to treating them as such. With the message box it generally happens not to matter that much because you generally won't ever try to do anything as silly as the following:

MsgBox "Added AbortRetryIgnore to YesNoCancel", vbAbortRetryIgnore + vbYesNoCancel
MsgBox "ORed AbortRetryIgnore with YesNoCancel", vbAbortRetryIgnore Or vbYesNoCancel

But eventually the day will come when you want to set bits in an existing mask for something (e.g. a windows style bits), where doing addition is likely to get you into trouble.

And on a final note: 'AND' will mask out prior bits, so:

MsgBox "oops", vbYesNoCancel And vbCritical

would give an undesired result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top