Using bit to know if options if set

dubem1

Newcomer
Joined
Dec 5, 2002
Messages
20
Let's explain myself.
I have a method to get an objet and is fellow data. The objet himself is a student, the fellow data are his address, his classes, his notes...and so on. I want a method where I can get only what I want.

Method Get(byval studentID as long, byval withAddress as boolean, byval with classes as boolean, byval with......)

It's a lot of parameters! I thought about using bit to know if an option is set.

Public Enum Options As Byte
Option1 = 1
Option2 = 2
Option3 = 4
Option4 = 8
Option5 = 16
Option6 = 32
End Enum

Method Get(byval studentID as long, byval opt as Options)

When I call the method, I can do

Get(34,Options.Option2 Or Options.Options5)

Then the byte representation should be
10010

So I know that Option2 is set and Option 5 is set.

Now it's where My problem is. Inside my Get method, I don't know how to analyse the byte to know that Option2 is set and Option 5 is set.

Do you know how can I get the binary representation of a byte and then check is bit to know if the option is set or not?

Thank you
Martin
 
Visual Basic:
Public Enum Options
Option1 = 1
Option2 = 2
Option3 = 4
Option4 = 8
Option5 = 16
Option6 = 32
End Enum

Dim E as Options = Options.Option1 Or Options.Option5
If (E And Options.Option5) = Options.Option5 Then
    Msgbox("Contained option5")
End If
 
Back
Top