VERSION 5.00 Begin VB.Form CollDemo Caption = "Collection Demo" ClientHeight = 4125 ClientLeft = 60 ClientTop = 345 ClientWidth = 5790 LinkTopic = "Form1" ScaleHeight = 4125 ScaleWidth = 5790 StartUpPosition = 3 'Windows Default Begin VB.ComboBox lstKey Enabled = 0 'False Height = 315 Left = 2880 Style = 2 'Dropdown List TabIndex = 5 Top = 1920 Width = 2535 End Begin VB.HScrollBar scrIndex Height = 375 Left = 600 TabIndex = 4 Top = 1920 Width = 1575 End Begin VB.OptionButton optKey Caption = "Key" Height = 495 Left = 3480 TabIndex = 3 Top = 1200 Width = 1455 End Begin VB.OptionButton optIndex Caption = "Index" Height = 255 Left = 720 TabIndex = 2 Top = 1320 Value = -1 'True Width = 975 End Begin VB.CommandButton cmdGo Caption = "Get it" Height = 735 Left = 1560 TabIndex = 0 Top = 2760 Width = 2655 End Begin VB.Label Label1 Caption = "Search by..." BeginProperty Font Name = "MS Sans Serif" Size = 18 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 840 TabIndex = 1 Top = 240 Width = 3255 End End Attribute VB_Name = "CollDemo" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False 'CollDemo 'By Andy Harris 'Demonstrates use of simple collections ' Dim People As New Collection Private SearchType As String Private Sub cmdGo_Click() If SearchType = "INDEX" Then MsgBox (People(scrIndex.Value)) ElseIf SearchType = "KEY" Then MsgBox (People(lstKey.Text)) End If End Sub Private Sub Form_Load() 'general initialization Dim person As String SearchType = "INDEX" 'add stuff to the collection 'Note use of the with structure to simplify syntax With People person = "Bill" .Add person, "President" person = "Hillary" .Add person, "Wife" person = "Chelsea" .Add person, "Daughter" person = "Socks" .Add person, "Cat" End With 'Initialize the scroll bar scrIndex.Max = People.Count 'note that the min on a collection is 1, 'but I'll leave this min to zero to test that assumption 'Initialize the list box lstKey.AddItem ("President") lstKey.AddItem ("Wife") lstKey.AddItem ("Daughter") lstKey.AddItem ("Cat") End Sub Private Sub optIndex_Click() If optIndex.Value = True Then scrIndex.Enabled = True lstKey.Enabled = False SearchType = "INDEX" End If End Sub Private Sub optKey_Click() If optKey.Value = True Then scrIndex.Enabled = False lstKey.Enabled = True SearchType = "KEY" End If End Sub Private Sub scrIndex_Change() optIndex.Caption = "Index (" + Str$(scrIndex.Value) + ")" End Sub