VERSION 5.00
Begin VB.Form frmNumCheck 
   Caption         =   "Form1"
   ClientHeight    =   5205
   ClientLeft      =   120
   ClientTop       =   450
   ClientWidth     =   4560
   LinkTopic       =   "Form1"
   ScaleHeight     =   5205
   ScaleWidth      =   4560
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdCheck 
      Caption         =   "Check Textboxes"
      Height          =   495
      Left            =   1680
      TabIndex        =   11
      Top             =   960
      Width           =   1935
   End
   Begin VB.CommandButton cmdAddRandom 
      Caption         =   "Add Random Numbers"
      Height          =   495
      Left            =   1680
      TabIndex        =   10
      Top             =   360
      Width           =   1935
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   9
      Left            =   480
      TabIndex        =   9
      Top             =   3600
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   8
      Left            =   480
      TabIndex        =   8
      Top             =   3240
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   7
      Left            =   480
      TabIndex        =   7
      Top             =   2880
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   6
      Left            =   480
      TabIndex        =   6
      Top             =   2520
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   5
      Left            =   480
      TabIndex        =   5
      Top             =   2160
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   4
      Left            =   480
      TabIndex        =   4
      Top             =   1800
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   3
      Left            =   480
      TabIndex        =   3
      Top             =   1440
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   2
      Left            =   480
      TabIndex        =   2
      Top             =   1080
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   1
      Left            =   480
      TabIndex        =   1
      Top             =   720
      Width           =   495
   End
   Begin VB.TextBox txtNumbers 
      Height          =   375
      Index           =   0
      Left            =   480
      TabIndex        =   0
      Top             =   360
      Width           =   495
   End
End
Attribute VB_Name = "frmNumCheck"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit


Private Sub cmdAddRandom_Click()
    ' Add test numbers to the textboxes
    AddRandomNumbers
    
End Sub

Private Sub ClearTextBoxes()
Dim i As Integer

    For i = 0 To 9
        txtNumbers(i).Text = ""
    Next i
End Sub

Private Sub AddRandomNumbers()
Dim col As Collection
Dim i As Integer
Dim r As Integer

    ' Clear all textboxes to start with
    ClearTextBoxes

    Set col = GetCollection
    
    For i = 0 To 7
        ' Get a random index for the collection
        r = Int(Rnd() * col.Count) + 1
        ' Add that collection item to the textbox
        txtNumbers(i).Text = col(r)
        ' Remove the collection item so it isn't reused
        col.Remove (r)
    Next i
    
    ' Cleanup
    Set col = Nothing
    
End Sub

Private Function GetCollection() As Collection
Dim col As Collection
Dim i As Integer
    
    Set col = New Collection

    ' Create a collection to initialize the textboxes
    For i = 0 To 9
        col.Add CStr(i), CStr(i)
    Next i
    
    Set GetCollection = col
    
    Set col = Nothing
End Function

Private Sub cmdCheck_Click()
Dim i As Integer
Dim col As Collection

    Set col = GetCollection
    
    ' Remove items from the collection that are found in the textboxes
    For i = 0 To 7
        col.Remove txtNumbers(i).Text
    Next i
    
    ' Deal with the results
    txtNumbers(8).BackColor = vbGreen
    txtNumbers(8).Text = col(1)
    
    txtNumbers(9).BackColor = vbGreen
    txtNumbers(9).Text = col(2)
    
    
    ' Cleanup
    Set col = Nothing
End Sub

Private Sub Form_Load()
    Randomize
End Sub
