Posts Tagged ‘enum’

How to use Bitwise in Vb.Net
    Enum eStatusNumber
        One = 1
        Two = 2
        Three = 4
        Four = 16
        Five = 32
    End Enum

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Test(eStatusNumber.Five Or eStatusNumber.Three)
    End Sub

    Private Sub Test(ByVal com As eStatusNumber)
        If (com And eStatusNumber.One) = eStatusNumber.One Then
            MsgBox("One")
        End If
        If (com And eStatusNumber.Two) = eStatusNumber.Two Then
            MsgBox("Two")
        End If

        If (com And eStatusNumber.Three) = eStatusNumber.Three Then
            MsgBox("Three")
        End If
        If (com And eStatusNumber.Four) = eStatusNumber.Four Then
            MsgBox("Four")
        End If

        If (com And eStatusNumber.Five) = eStatusNumber.Five Then
            MsgBox("Five")
        End If

    End Sub

VB.Net code can be downloaded here "EnumBitWise Sample".
Reference 1
Reference 2

				

, ,

No Comments


Enum: How to get the underlying value given the name

Use Parse method of the enum to get the value:

Enum x
a = 1
b = 2
End Enum

dim e as x

e = [enum].Parse(GetType(x), “a”)

,

No Comments



SetPageWidth