BitArrayStatic |
Name | Description |
---|---|
FromBooleans | Returns a BitArray object created from an array of Booleans. Each boolean represents a single bit in the bit array. |
FromBytes | Returns a BitArray object created from an array of Bytes. Each bit in each byte represents an associated bit in the bit array. |
FromLongs | Returns a BitArray object created from an array of Longs. Each bit in each long represents an associated bit in the bit array. |
This class cannot be directly instantiated. In order to use the methods in the class, use the BitArray.MethodName syntax.
The following code example shows how to create and initialize a BitArray and how to print out its values.
Private Sub Main() Const CountFormatter As String = " Count: {0}" Const LengthFormatter As String = " Length: {0}" Dim MyBA1 As BitArray Dim MyBA2 As BitArray Dim MyBA3 As BitArray Dim MyBA4 As BitArray Dim MyBA5 As BitArray ' Creates and initializes several BitArrays. Set MyBA1 = NewBitArray(5) Set MyBA2 = NewBitArray(5, True) Set MyBA3 = BitArray.FromBytes(NewBytes(1, 2, 3, 4, 5)) Set MyBA4 = BitArray.FromBooleans(NewBooleans(True, False, True, True, False)) Set MyBA5 = BitArray.FromLongs(NewLongs(6, 7, 8, 9, 10)) ' Displays the properties and values of the BitArrays. Debug.Print "MyBA1" Debug.Print CorString.Format(CountFormatter, MyBA1.Count) Debug.Print CorString.Format(CountFormatter, MyBA1.Length) Debug.Print " Values:" PrintValues MyBA1, 8 Debug.Print "MyBA2" Debug.Print CorString.Format(CountFormatter, MyBA2.Count) Debug.Print CorString.Format(CountFormatter, MyBA2.Length) Debug.Print " Values:" PrintValues MyBA2, 8 Debug.Print "MyBA3" Debug.Print CorString.Format(CountFormatter, MyBA3.Count) Debug.Print CorString.Format(CountFormatter, MyBA3.Length) Debug.Print " Values:" PrintValues MyBA3, 8 Debug.Print "MyBA4" Debug.Print CorString.Format(CountFormatter, MyBA4.Count) Debug.Print CorString.Format(CountFormatter, MyBA4.Length) Debug.Print " Values:" PrintValues MyBA4, 8 Debug.Print "MyBA5" Debug.Print CorString.Format(CountFormatter, MyBA5.Count) Debug.Print CorString.Format(CountFormatter, MyBA5.Length) Debug.Print " Values:" PrintValues MyBA5, 8 End Sub Private Sub PrintValues(ByVal MyList As IEnumerable, ByVal MyWidth As Long) Dim i As Long Dim Value As Variant i = MyWidth For Each Value In MyList If i <= 0 Then i = MyWidth Debug.Print End If i = i - 1 Debug.Print CorString.Format("{0,8}", Value); Next Debug.Print End Sub ' This code produces the following output. ' ' MyBA1 ' Count: 5 ' Count: 5 ' Values: ' False False False False False ' MyBA2 ' Count: 5 ' Count: 5 ' Values: ' True True True True True ' MyBA3 ' Count: 40 ' Count: 40 ' Values: ' True False False False False False False False ' False True False False False False False False ' True True False False False False False False ' False False True False False False False False ' True False True False False False False False ' MyBA4 ' Count: 5 ' Count: 5 ' Values: ' True False True True False ' MyBA5 ' Count: 160 ' Count: 160 ' Values: ' False True True False False False False False ' False False False False False False False False ' False False False False False False False False ' False False False False False False False False ' True True True False False False False False ' False False False False False False False False ' False False False False False False False False ' False False False False False False False False ' False False False True False False False False ' False False False False False False False False ' False False False False False False False False ' False False False False False False False False ' True False False True False False False False ' False False False False False False False False ' False False False False False False False False ' False False False False False False False False ' False True False True False False False False ' False False False False False False False False ' False False False False False False False False ' False False False False False False False False