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-4-2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-19  |  2.0 KB  |  70 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_4_2 
  3.    Caption         =   "Stone Age Friends"
  4.    ClientHeight    =   972
  5.    ClientLeft      =   1068
  6.    ClientTop       =   1920
  7.    ClientWidth     =   6300
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   7.8
  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     =   972
  20.    ScaleWidth      =   6300
  21.    Begin VB.PictureBox picNames 
  22.       Height          =   255
  23.       Left            =   120
  24.       ScaleHeight     =   204
  25.       ScaleWidth      =   5964
  26.       TabIndex        =   1
  27.       Top             =   600
  28.       Width           =   6012
  29.    End
  30.    Begin VB.CommandButton cmdSort 
  31.       Caption         =   "Perform a Bubble Sort"
  32.       Height          =   375
  33.       Left            =   1440
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   3015
  37.    End
  38. Attribute VB_Name = "frm7_4_2"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Dim nom(1 To 5) As String
  44. Private Sub cmdSort_Click()
  45.   Dim passNum As Integer, i As Integer, temp As String
  46.   'Bubble sort names
  47.   For passNum = 1 To 4    'Number of passes is 1 less than number of items
  48.     For i = 1 To 5 - passNum            'Each pass needs 1 less comparison
  49.       If nom(i) > nom(i + 1) Then
  50.           temp = nom(i)
  51.           nom(i) = nom(i + 1)
  52.           nom(i + 1) = temp
  53.       End If
  54.     Next i
  55.   Next passNum
  56.   'Display alphabetized list
  57.   picNames.Cls
  58.   For i = 1 To 5
  59.     picNames.Print nom(i),
  60.   Next i
  61. End Sub
  62. Private Sub Form_Load()
  63.   'Fill array with names
  64.   nom(1) = "Pebbles"
  65.   nom(2) = "Barney"
  66.   nom(3) = "Wilma"
  67.   nom(4) = "Fred"
  68.   nom(5) = "Dino"
  69. End Sub
  70.