VERSION 4.00 Begin VB.Form Form1 Caption = "Sieve Test" ClientHeight = 2820 ClientLeft = 3792 ClientTop = 2688 ClientWidth = 4728 Height = 3204 Left = 3744 LinkTopic = "Form1" ScaleHeight = 2820 ScaleWidth = 4728 Top = 2352 Width = 4824 Begin VB.TextBox Text1 Height = 492 Left = 2280 TabIndex = 0 Top = 1200 Width = 972 End Begin VB.CommandButton Command1 Caption = "Start sieving" Height = 492 Left = 2280 TabIndex = 1 Top = 2280 Width = 972 End Begin VB.Label Label1 Caption = "Enter the ending number" Height = 492 Left = 840 TabIndex = 2 Top = 1200 Width = 1092 End End Attribute VB_Name = "Form1" Attribute VB_Creatable = False Attribute VB_Exposed = False Private Sub Command1_Click() Dim testArray As New BitArray Dim Size As Long, Foo As Variant Foo = Text1.Text If Not IsNumeric(Foo) Then MsgBox ("Enter a number please") Text1.Text = "" Text1.SetFocus Exit Sub End If Size = Val(Text1.Text) theTime = Timer testArray.BitSet = Size Dim I As Long, Count As Long, K As Long For I = 1 To Size testArray.turnOnBit = I Next I I = 2 Do While I * I <= Size If testArray.getBit(I) Then K = 2 * I Do While K <= Size testArray.turnOffBit = K K = I + K Loop End If I = I + 1 Loop For I = 2 To Size If testArray.getBit(I) Then Count = Count + 1 Next I Cls Print "There are"; Count; " primes up to"; Size; "." Print "Total time taken was "; Timer - theTime; " seconds." Set testArray = Nothing End Sub