|
-
May 9th, 2005, 07:26 AM
#1
Thread Starter
Frenzied Member
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:
<Flags()> _
Enum myButtons
[Next] = 1
Back = 2
Cancel = 4
'...
End Enum
Public Sub ShowButtons(buttons as myButtons)
'...?
End Sub
'...
'Some other sub
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)
-
May 9th, 2005, 07:57 AM
#2
Re: Enums and Bit Fields
Use the AND operator. the OR is used to set bits not query them.
VB Code:
If (Data AND myButtons.Back) > 0 then 'back pressed
I don't live here any more.
-
May 11th, 2005, 03:43 AM
#3
Thread Starter
Frenzied Member
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)
-
May 11th, 2005, 03:47 AM
#4
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.
-
May 11th, 2005, 03:53 AM
#5
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|