Results 1 to 5 of 5

Thread: Enums and Bit Fields [Resolved]

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Resolved Enums and Bit Fields [Resolved]

    When you use bit fields with enumerated data types, you can use the elements in the Enum as flags. Now I know that you have to add the <Flags()> attribute to an Enum to turn this behaviour on, and there's no problems there, however, how do you find out the combination of values that has been set?

    For example:
    VB Code:
    1. <Flags()> _
    2. Enum myButtons
    3.     [Next] = 1
    4.     Back = 2
    5.     Cancel = 4
    6.     '...
    7. End Enum
    8.  
    9. Public Sub ShowButtons(buttons as myButtons)
    10.     '...?
    11. End Sub
    12.  
    13. '...
    14. 'Some other sub
    15. Call ShowButtons(myButtons.Next Or myButtons.Back)
    How do you get which buttons were passed so you can work on them?
    Last edited by Ideas Man; May 11th, 2005 at 03:45 AM.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Enums and Bit Fields

    Use the AND operator. the OR is used to set bits not query them.

    VB Code:
    1. If (Data AND myButtons.Back) > 0 then 'back pressed
    I don't live here any more.

  3. #3

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Enums and Bit Fields

    You legend, thanks heaps for that. I knew it would have to be something simple, pity it's not easily visible in the MSDN documentation or with a Google search.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Enums and Bit Fields

    Well its nothing more than elementary binary arithmatic, its the normal way to check flags on most languages / platforms. Its worth swotting up on Binary ops anyway.

    AND OR NOT XOR... also Bit Masks and shifting.
    I don't live here any more.

  5. #5

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Enums and Bit Fields [Resolved]

    Well, all of that is news to me. I know none of that, lol.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width