Correct way to combine MsgboxStyles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paragpdoke
    New Member
    • Dec 2007
    • 62

    Correct way to combine MsgboxStyles

    Hello Everyone.
    I have a basic VB.NET question (again).
    I found people using various ways to combine MsgboxStyles in VB.NET. For example:
    Code:
    MsgBoxStyle.Question + MsgBoxStyle.YesNo
    MsgBoxStyle.Question Or MsgBoxStyle.YesNo
    MsgBoxStyle.Question | MsgBoxStyle.YesNo
    All seem to work. Which one is the right way to follow ? I searched this on MSDN and reached:

    But this does not seem to tell how to combine the styles.

    Thank you in advance,
    Parag Doke
    Last edited by debasisdas; May 28 '09, 12:33 PM. Reason: thread moved to vb.net section of the forum.
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    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.Que stion and MsgBoxStyle.Yes No 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. :)

    Comment

    • paragpdoke
      New Member
      • Dec 2007
      • 62

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

      Regards,
      Parag Doke

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        The values of the MsgBoxStyle enumeration are shown here: MsgBox Function. They are designed such that they may be added together.

        Comment

        • paragpdoke
          New Member
          • Dec 2007
          • 62

          #5
          Thank you ChipR for the link.

          Regards,
          Parag Doke

          Comment

          Working...