In situations such as this one, I usually prefer to use good old-fashioned bit-fields, as examplified by:
VB.NET Code:
<FlagsAttribute()> Public Enum MyBitfield IsFontColour = &H1 'Value gets doubled for each field so each one occupy a single bit of a 32 bit number (ie. max 32 entries). IsFontSize = &H2 IsWidth = &H4 IsHeight = &H8 IsMarginL = &H10 IsMarginR = &H20 IsSpeed = &H40 IsEasing = &H80 End Enum Public Class MyBitClass Public Function TestBitfields(ByVal sBitValue As MyBitfield) As Boolean 'Set test to hold True for IsFontSize, IsSpeed and IsHeight and False for all others fields. Dim test As MyBitfield = MyBitfield.IsFontSize Or MyBitfield.IsSpeed Or MyBitfield.IsHeight If (sBitValue And test) = test Then 'Simultaneous test for 3 True and 5 False booleans '... End If 'Can also be used as: If (sBitValue And &HCB) <> 0 Then 'I get to here, if one of IsEasing, IsSpeed, IsHeight, IsFontSize or IsFontColour is True. End If Return test = MyBitfield.IsMarginL End Function End Class




Reply With Quote