VERSION 5.00
Begin VB.Form frmSplit 
   Caption         =   "Split and InStr"
   ClientHeight    =   5340
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form2"
   ScaleHeight     =   5340
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox List1 
      Height          =   4545
      Left            =   120
      TabIndex        =   3
      Top             =   600
      Width           =   4455
   End
   Begin VB.TextBox Text2 
      Alignment       =   1  'Right Justify
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   120
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Bits"
      Default         =   -1  'True
      Height          =   375
      Left            =   2520
      TabIndex        =   0
      Top             =   120
      Width           =   1815
   End
   Begin VB.Label Label1 
      Caption         =   "Permutations of:"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   240
      Width           =   1215
   End
End
Attribute VB_Name = "frmSplit"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Const bONE = "1"
Private Const bZERO = "0"

Private Sub Command1_Click()
'Generates the different possible arrangements of 1s and 0s
'for a given number of bits
Dim BitArray() As String
Dim Bound As Long
Dim idx As Integer
Dim strFormat As String
Dim bLoop As Integer

If Text2.Text = "" Or IsNumeric(Text2.Text) = False Then Exit Sub

Me.MousePointer = vbHourglass
List1.Clear
strFormat = String(CLng(Text2.Text), bZERO) 'create a format string
Bound = 2 ^ CInt(Text2.Text) - 1 'calculate the size of the array
ReDim BitArray(Bound) As String

BitArray(0) = bZERO
BitArray(1) = bONE
bLoop = 1

For idx = 2 To (Bound) Step 2
'Generate the actual arrangements. we go in steps of 2 because
'for each old arrangement, there will be 2 new arrangements; one
'for 0 and one for 1.
  BitArray(idx) = BitArray(idx - bLoop) & bZERO 'Create the new 0 arrangement
  BitArray(idx + 1) = BitArray(idx - bLoop) & bONE 'Create the new 1 arrangement
  bLoop = bLoop + 1 ' - this counter ensures the length of the arrangements
Next idx            '   is the same.

For idx = 0 To (Bound)
 'add the arrangements to the listbox
 List1.AddItem Format$(BitArray(idx), strFormat)
Next idx

Me.MousePointer = vbArrow
End Sub


Private Sub Form_Activate()
Text2.SetFocus
End Sub
