home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-2-3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  2.8 KB  |  101 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_2_3 
  3.    Caption         =   "Merging Lists"
  4.    ClientHeight    =   960
  5.    ClientLeft      =   1005
  6.    ClientTop       =   1920
  7.    ClientWidth     =   4080
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   960
  20.    ScaleWidth      =   4080
  21.    Begin VB.PictureBox picMergedList 
  22.       Height          =   255
  23.       Left            =   240
  24.       ScaleHeight     =   195
  25.       ScaleWidth      =   3675
  26.       TabIndex        =   1
  27.       Top             =   600
  28.       Width           =   3735
  29.    End
  30.    Begin VB.CommandButton cmdMerge 
  31.       Caption         =   "Merge Lists of Names"
  32.       Height          =   375
  33.       Left            =   840
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   2535
  37.    End
  38. Attribute VB_Name = "frm7_2_3"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. 'Create arrays to hold list of names
  44. Dim list1(1 To 5) As String, list2(1 To 5) As String
  45. Dim newList(1 To 10) As String
  46. Private Sub cmdMerge_Click()
  47.   Dim m As Integer, n As Integer, r As Integer
  48.   Dim numNames As Integer, i As Integer
  49.   'Merge two lists of names
  50.   m = 1   'Subscript for first array
  51.   n = 1   'Subscript for second array
  52.   r = 1   'Subscript and counter for third array
  53.   Do While (m <= 5) And (n <= 5)
  54.     Select Case list1(m)
  55.       Case Is < list2(n)
  56.         newList(r) = list1(m)
  57.         m = m + 1
  58.       Case Is > list2(n)
  59.         newList(r) = list2(n)
  60.         n = n + 1
  61.       Case list2(n)
  62.         newList(r) = list1(m)
  63.         m = m + 1
  64.         n = n + 1
  65.     End Select
  66.     r = r + 1
  67.   Loop
  68.   'If one of the lists has items left over, copy them into the third list.
  69.   'At most one of the following two loops will be executed.
  70.   Do While m <= 5       'Copy rest of first array into third
  71.     newList(r) = list1(m)
  72.     r = r + 1
  73.     m = m + 1
  74.   Loop
  75.   Do While n <= 5      'Copy rest of second array into third
  76.     newList(r) = list2(n)
  77.     r = r + 1
  78.     n = n + 1
  79.   Loop
  80.   numNames = r - 1
  81.   'Show result of merging lists
  82.   picMergedList.Cls
  83.   For i = 1 To numNames
  84.     picMergedList.Print newList(i) & "  ";
  85.   Next i
  86. End Sub
  87. Private Sub Form_Load()
  88.   'Fill list1 with names
  89.   list1(1) = "Al"
  90.   list1(2) = "Carl"
  91.   list1(3) = "Don"
  92.   list1(4) = "Greg"
  93.   list1(5) = "Judy"
  94.   'Fill list2 with names
  95.   list2(1) = "Bob"
  96.   list2(2) = "Carl"
  97.   list2(3) = "Eric"
  98.   list2(4) = "Greg"
  99.   list2(5) = "Herb"
  100. End Sub
  101.