Doh!
I defined Enum Bit incorrectly, the function wants the mask for the bits,
not the index of said bits. Try the following Enum instead.
Private Enum Bit
A = 1 << 0
B = 1 << 1
C = 1 << 2
D = 1 << 3
End Enum
If you use VB.NET 2002 try:
Private Enum Bit
A = 1
B = 2
C = 4
D = 8
End Enum
Hope this helps
Jay
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:OL******** ******@TK2MSFTN GP15.phx.gbl...
| QuocSi,
| As OHM suggests I would consider either a BitArray or a BitVector32.
|
|
http://msdn.microsoft.com/library/de...classtopic.asp
|
|
http://msdn.microsoft.com/library/de...classtopic.asp
|
| OHM showed the BitArray, here is a BetVector32 sample:
|
| Public Structure MyBits
|
| Private Enum Bit
| A
| B
| C
| D
| End Enum
|
| Private m_value As BitVector32
|
| Public Sub New(ByVal data As Int32)
| m_value = New BitVector32(dat a)
| End Sub
|
| Public Property a() As Boolean
| Get
| Return m_value.Item(Bi t.A)
| End Get
| Set(ByVal value As Boolean)
| m_value.Item(Bi t.A) = value
| End Set
| End Property
|
| Public Property b() As Boolean
| Get
| Return m_value.Item(Bi t.B)
| End Get
| Set(ByVal value As Boolean)
| m_value.Item(Bi t.B) = value
| End Set
| End Property
|
| Public Property c() As Boolean
| Get
| Return m_value.Item(Bi t.C)
| End Get
| Set(ByVal value As Boolean)
| m_value.Item(Bi t.C) = value
| End Set
| End Property
|
| Public Property d() As Boolean
| Get
| Return m_value.Item(Bi t.D)
| End Get
| Set(ByVal value As Boolean)
| m_value.Item(Bi t.D) = value
| End Set
| End Property
|
| Public Function ToInt16() As Int16
| Return CShort(m_value. Data)
| End Function
|
| Public Function ToInt32() As Int32
| Return m_value.Data
| End Function
|
| Public Shared Function FromInt16(ByVal value As Int16) As MyBits
| Return New MyBits(value)
| End Function
|
| Public Shared Function FromInt32(ByVal value As Int32) As MyBits
| Return New MyBits(value)
| End Function
|
| End Structure
|
|
| Hope this helps
| Jay
|
| "QuocSi" <pq*@pqsweb.com > wrote in message
| news:42******** **************@ news.free.fr...
|| Hi all,
||
|| I have a bitsfield
||
|| Structure MyBits
|| a as boolean
|| b as boolean
|| c as boolean
|| d as boolean
|| end structure
||
|| I wish to convert it into an Int16 from the binary value of my structure.
||
|| Thanks for your help
||
||
||
|
|