Connecting Tech Pros Worldwide Forums | Help | Site Map

Correct way to combine MsgboxStyles

Member
 
Join Date: Dec 2007
Location: Pune, India
Posts: 46
#1: May 28 '09
Hello Everyone.
I have a basic VB.NET question (again).
I found people using various ways to combine MsgboxStyles in VB.NET. For example:
Expand|Select|Wrap|Line Numbers
  1. MsgBoxStyle.Question + MsgBoxStyle.YesNo
  2. MsgBoxStyle.Question Or MsgBoxStyle.YesNo
  3. MsgBoxStyle.Question | MsgBoxStyle.YesNo
  4.  
All seem to work. Which one is the right way to follow ? I searched this on MSDN and reached:
http://msdn.microsoft.com/hi-in/libr...s,loband).aspx
But this does not seem to tell how to combine the styles.

Thank you in advance,
Parag Doke

nukefusion's Avatar
Expert
 
Join Date: Mar 2008
Location: Essex, UK
Posts: 197
#2: May 29 '09

re: Correct way to combine MsgboxStyles


Hi paragpdoke,

The MsgBoxStyle is an enumeration defined with the Flags attribute. That means you should use bitwise operations against them rather than arithmetic operations.

In terms of the examples you've posted I would say the first one is incorrect as it uses an arithmetic operator. That would probably give you the underlying integer values of MsgBoxStyle.Question and MsgBoxStyle.YesNo added together, which may or may not equate to another member of the enumeration, which, although allowed, is more than likely not what you're looking for.

Not that knowledgeable on VB, but the second one looks like VB syntax and would be equivalent to the third one which looks like C# syntax. Both OR the two flags together.

Of course you can always AND the flags together. This would use "And" in VB or the & operator in C#.

It may be worth looking up some resources on Bitwise operators and how they work in both VB and C#.

Hope this helps. :)
Member
 
Join Date: Dec 2007
Location: Pune, India
Posts: 46
#3: May 29 '09

re: Correct way to combine MsgboxStyles


Hello nukefusion.
Yes, your reply definitely helps.
Thank you for taking out the time to share the information.

Regards,
Parag Doke
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,175
#4: Jun 1 '09

re: Correct way to combine MsgboxStyles


The values of the MsgBoxStyle enumeration are shown here: MsgBox Function. They are designed such that they may be added together.
Member
 
Join Date: Dec 2007
Location: Pune, India
Posts: 46
#5: Jun 1 '09

re: Correct way to combine MsgboxStyles


Thank you ChipR for the link.

Regards,
Parag Doke
Reply

Tags
vb.net messagebox style