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-3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  3.2 KB  |  104 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_4_3 
  3.    Caption         =   "Metropolitan Statistics"
  4.    ClientHeight    =   3765
  5.    ClientLeft      =   1140
  6.    ClientTop       =   2190
  7.    ClientWidth     =   6915
  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     =   3765
  20.    ScaleWidth      =   6915
  21.    Begin VB.PictureBox picTable 
  22.       Height          =   2895
  23.       Left            =   120
  24.       ScaleHeight     =   2835
  25.       ScaleWidth      =   6435
  26.       TabIndex        =   1
  27.       Top             =   720
  28.       Width           =   6492
  29.    End
  30.    Begin VB.CommandButton cmdDisplayStats 
  31.       Caption         =   "Display Statistics on 10 Most Populous Metropolitan Areas"
  32.       Height          =   495
  33.       Left            =   720
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   5295
  37.    End
  38. Attribute VB_Name = "frm7_4_3"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Dim city(1 To 10) As String, pop(1 To 10) As Single, income(1 To 10) As Single
  44. Dim natives(1 To 10) As Single, advDeg(1 To 10) As Single
  45. Private Sub cmdDisplayStats_Click()
  46.   Call SortData
  47.   Call ShowData
  48. End Sub
  49. Private Sub Form_Load()
  50.   Dim i As Integer
  51.   'Assume that the data for city name, population, medium income, % native,
  52.   'and % advanced degree have been placed in the file "CITYSTAT.TXT"
  53.   '(First line of file is "Boston",4.2,4066,73,12)
  54.   Open App.Path & "\CITYSTAT.TXT" For Input As #1
  55.   For i = 1 To 10
  56.     Input #1, city(i), pop(i), income(i), natives(i), advDeg(i)
  57.   Next i
  58.   Close #1
  59. End Sub
  60. Private Sub ShowData()
  61.   Dim i As Integer
  62.   'Display ordered table
  63.   picTable.Cls
  64.   picTable.Print , "Pop. in", "Med. income", "% Native", "% Advanced"
  65.   picTable.Print "Metro Area", "millions", "per hsd", "to State", "Degree"
  66.   picTable.Print
  67.   For i = 1 To 10
  68.     picTable.Print city(i); Tab(16); pop(i), income(i), natives(i), advDeg(i)
  69.   Next i
  70. End Sub
  71. Private Sub SortData()
  72.   Dim passNum As Integer, index As Integer
  73.   'Bubble sort table in descending order by population
  74.   For passNum = 1 To 9
  75.     For index = 1 To 10 - passNum
  76.       If pop(index) < pop(index + 1) Then
  77.           Call SwapData(index)
  78.       End If
  79.     Next index
  80.   Next passNum
  81. End Sub
  82. Private Sub SwapData(index As Integer)
  83.   'Swap entries
  84.   Call SwapStr(city(index), city(index + 1))
  85.   Call SwapNum(pop(index), pop(index + 1))
  86.   Call SwapNum(income(index), income(index + 1))
  87.   Call SwapNum(natives(index), natives(index + 1))
  88.   Call SwapNum(advDeg(index), advDeg(index + 1))
  89. End Sub
  90. Private Sub SwapNum(a As Single, b As Single)
  91.   Dim temp As Single
  92.   'Interchange values of a and b
  93.   temp = a
  94.   a = b
  95.   b = temp
  96. End Sub
  97. Private Sub SwapStr(a As String, b As String)
  98.   Dim temp As String
  99.   'Interchange values of a and b
  100.   temp = a
  101.   a = b
  102.   b = temp
  103. End Sub
  104.