Class: BitArray in Category General VBA/VB6 : Abstract Data Types from Total Visual SourceBook

Class that implements a bit array in VBA and VB6.

A bit array is an array of bit values, defined as 0 or 1. This class allocates 1 bit for each value you wish to store, resulting in significant memory savings. For example, suppose you wanted to maintain an array of 100 Boolean values. A single Boolean requires 2 bytes of memory, resulting in 200 bytes of memory. Using the bit-array technique available with this class, only 13 bytes of memory are consumed. A zero in the bit array would represent False, and a 1, True.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the CBitArray class.
Bit Property Get the value of the bit specified in the lngBitNumber parameter.
BitCount Property Get the number of bits that are set in the bit array.
Count Property Get the number of bits represented in this class.
' Example of CBitArray
' To try this example, do the following:
' 1. Create a new form
' 2. Add a command button 'cmdTest'
' 3. Paste all the code from this example to the new form's module
' 4. Run the form

Private Sub cmdTest_Click()
  Dim BitOps As CBitArray
  Dim lngCounter As Long

  Set BitOps = New CBitArray

  ' Set the number of bits to hold
  BitOps.Count = 100

  ' Set every 10 bits
  For lngCounter = 0 To 100 Step 10
    BitOps.Bit(lngCounter) = True
  Next lngCounter

  ' Test every five bits
  For lngCounter = 0 To 100 Step 5
    Debug.Print "Bit Number " & lngCounter & " is " & BitOps.Bit(lngCounter)
  Next lngCounter

  ' Indicate how many bits are set
  Debug.Print BitOps.BitCount & " bits are set to true"
End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

View all FMS products for Microsoft Access All Our Microsoft Access Products


Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info




Free Product Catalog from FMS