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 / CH4 / 4-1-6.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-19  |  2.1 KB  |  66 lines

  1. VERSION 5.00
  2. Begin VB.Form frmStates 
  3.    Caption         =   "State Demographics"
  4.    ClientHeight    =   1620
  5.    ClientLeft      =   1128
  6.    ClientTop       =   1656
  7.    ClientWidth     =   4944
  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.    ForeColor       =   &H80000008&
  18.    LinkTopic       =   "Form1"
  19.    PaletteMode     =   1  'UseZOrder
  20.    ScaleHeight     =   1620
  21.    ScaleWidth      =   4944
  22.    Begin VB.CommandButton cmdDisplay 
  23.       Caption         =   "Display Demographics"
  24.       Default         =   -1  'True
  25.       Height          =   495
  26.       Left            =   840
  27.       TabIndex        =   1
  28.       Top             =   240
  29.       Width           =   3375
  30.    End
  31.    Begin VB.PictureBox picDensity 
  32.       Height          =   495
  33.       Left            =   120
  34.       ScaleHeight     =   444
  35.       ScaleWidth      =   4644
  36.       TabIndex        =   0
  37.       Top             =   960
  38.       Width           =   4695
  39.    End
  40. Attribute VB_Name = "frmStates"
  41. Attribute VB_GlobalNameSpace = False
  42. Attribute VB_Creatable = False
  43. Attribute VB_PredeclaredId = True
  44. Attribute VB_Exposed = False
  45. Private Sub cmdDisplay_Click()
  46.   Dim state As String, pop As Single, area As Single
  47.   Dim s As String, p As Single, a As Single
  48.   'Calculate the population densities of states
  49.   picDensity.Cls
  50.   Open App.Path & "\DEMOGRAP.TXT" For Input As #1
  51.   Input #1, state, pop, area
  52.   Call CalculateDensity(state, pop, area)
  53.   Input #1, s, p, a
  54.   Call CalculateDensity(s, p, a)
  55.   Close #1
  56. End Sub
  57. Private Sub CalculateDensity(state As String, pop As Single, area As Single)
  58.   Dim rawDensity As Single, density As Single
  59.   'The density (number of people per square mile)
  60.   'will be rounded to a whole number
  61.   rawDensity = pop / area
  62.   density = Round(rawDensity)
  63.   picDensity.Print "The density of "; state; " is"; density;
  64.   picDensity.Print "people per square mile."
  65. End Sub
  66.