home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frm7_4_3
- Caption = "Metropolitan Statistics"
- ClientHeight = 3765
- ClientLeft = 1140
- ClientTop = 2190
- ClientWidth = 6915
- 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 = 3765
- ScaleWidth = 6915
- Begin VB.PictureBox picTable
- Height = 2895
- Left = 120
- ScaleHeight = 2835
- ScaleWidth = 6435
- TabIndex = 1
- Top = 720
- Width = 6492
- End
- Begin VB.CommandButton cmdDisplayStats
- Caption = "Display Statistics on 10 Most Populous Metropolitan Areas"
- Height = 495
- Left = 720
- TabIndex = 0
- Top = 120
- Width = 5295
- End
- Attribute VB_Name = "frm7_4_3"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim city(1 To 10) As String, pop(1 To 10) As Single, income(1 To 10) As Single
- Dim natives(1 To 10) As Single, advDeg(1 To 10) As Single
- Private Sub cmdDisplayStats_Click()
- Call SortData
- Call ShowData
- End Sub
- Private Sub Form_Load()
- Dim i As Integer
- 'Assume that the data for city name, population, medium income, % native,
- 'and % advanced degree have been placed in the file "CITYSTAT.TXT"
- '(First line of file is "Boston",4.2,4066,73,12)
- Open App.Path & "\CITYSTAT.TXT" For Input As #1
- For i = 1 To 10
- Input #1, city(i), pop(i), income(i), natives(i), advDeg(i)
- Next i
- Close #1
- End Sub
- Private Sub ShowData()
- Dim i As Integer
- 'Display ordered table
- picTable.Cls
- picTable.Print , "Pop. in", "Med. income", "% Native", "% Advanced"
- picTable.Print "Metro Area", "millions", "per hsd", "to State", "Degree"
- picTable.Print
- For i = 1 To 10
- picTable.Print city(i); Tab(16); pop(i), income(i), natives(i), advDeg(i)
- Next i
- End Sub
- Private Sub SortData()
- Dim passNum As Integer, index As Integer
- 'Bubble sort table in descending order by population
- For passNum = 1 To 9
- For index = 1 To 10 - passNum
- If pop(index) < pop(index + 1) Then
- Call SwapData(index)
- End If
- Next index
- Next passNum
- End Sub
- Private Sub SwapData(index As Integer)
- 'Swap entries
- Call SwapStr(city(index), city(index + 1))
- Call SwapNum(pop(index), pop(index + 1))
- Call SwapNum(income(index), income(index + 1))
- Call SwapNum(natives(index), natives(index + 1))
- Call SwapNum(advDeg(index), advDeg(index + 1))
- End Sub
- Private Sub SwapNum(a As Single, b As Single)
- Dim temp As Single
- 'Interchange values of a and b
- temp = a
- a = b
- b = temp
- End Sub
- Private Sub SwapStr(a As String, b As String)
- Dim temp As String
- 'Interchange values of a and b
- temp = a
- a = b
- b = temp
- End Sub
-