home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frm7_2_3
- Caption = "Merging Lists"
- ClientHeight = 960
- ClientLeft = 1005
- ClientTop = 1920
- ClientWidth = 4080
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 960
- ScaleWidth = 4080
- Begin VB.PictureBox picMergedList
- Height = 255
- Left = 240
- ScaleHeight = 195
- ScaleWidth = 3675
- TabIndex = 1
- Top = 600
- Width = 3735
- End
- Begin VB.CommandButton cmdMerge
- Caption = "Merge Lists of Names"
- Height = 375
- Left = 840
- TabIndex = 0
- Top = 120
- Width = 2535
- End
- Attribute VB_Name = "frm7_2_3"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- 'Create arrays to hold list of names
- Dim list1(1 To 5) As String, list2(1 To 5) As String
- Dim newList(1 To 10) As String
- Private Sub cmdMerge_Click()
- Dim m As Integer, n As Integer, r As Integer
- Dim numNames As Integer, i As Integer
- 'Merge two lists of names
- m = 1 'Subscript for first array
- n = 1 'Subscript for second array
- r = 1 'Subscript and counter for third array
- Do While (m <= 5) And (n <= 5)
- Select Case list1(m)
- Case Is < list2(n)
- newList(r) = list1(m)
- m = m + 1
- Case Is > list2(n)
- newList(r) = list2(n)
- n = n + 1
- Case list2(n)
- newList(r) = list1(m)
- m = m + 1
- n = n + 1
- End Select
- r = r + 1
- Loop
- 'If one of the lists has items left over, copy them into the third list.
- 'At most one of the following two loops will be executed.
- Do While m <= 5 'Copy rest of first array into third
- newList(r) = list1(m)
- r = r + 1
- m = m + 1
- Loop
- Do While n <= 5 'Copy rest of second array into third
- newList(r) = list2(n)
- r = r + 1
- n = n + 1
- Loop
- numNames = r - 1
- 'Show result of merging lists
- picMergedList.Cls
- For i = 1 To numNames
- picMergedList.Print newList(i) & " ";
- Next i
- End Sub
- Private Sub Form_Load()
- 'Fill list1 with names
- list1(1) = "Al"
- list1(2) = "Carl"
- list1(3) = "Don"
- list1(4) = "Greg"
- list1(5) = "Judy"
- 'Fill list2 with names
- list2(1) = "Bob"
- list2(2) = "Carl"
- list2(3) = "Eric"
- list2(4) = "Greg"
- list2(5) = "Herb"
- End Sub
-