BitOr and BitAnd Not sure how to compare values

S

Sam

Say you have

Bold = 1 (100)
Italic = 2 (010)
Underline = 4 (001)

So the possible style values are:
Bold = 1
Italic = 2
Bold & Italic = 3 (110)
Underline = 4
Bold & Underline = 5 (101)
Italic & Underline = 6 (011)
Bold, Italic, & Underline = 7 (111)

In code how do I determine by the style number if the text should be italic.

I thought there was someway to do a bitwise AND or OR.

Is Italic in 5? FALSE
Is Italic in 3? TRUE, and so forth.

I'm working in VB.Net.

Thanks...
 
J

Jay B. Harlow [MVP - Outlook]

Sam,
Assuming you have:

<Flags> Public Enum Style
Bold = 1
Italic = 2
Underline = 4
End Enum

You can check a value for Italic using something like:

Dim s As Style
If (s And Style.Italic) = Italic Then
' The style has italic in it
End If

Some people will use "(s And Style.Italic) <> 0" which also works.

You can use Or to combine styles

s = Style.Bold Or Style.Italic

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top