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-5-1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  4.1 KB  |  138 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDist 
  3.    Caption         =   "Intercity Distances"
  4.    ClientHeight    =   2325
  5.    ClientLeft      =   2580
  6.    ClientTop       =   1590
  7.    ClientWidth     =   4335
  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     =   2325
  20.    ScaleWidth      =   4335
  21.    Begin VB.PictureBox picMiles 
  22.       Height          =   255
  23.       Left            =   840
  24.       ScaleHeight     =   195
  25.       ScaleWidth      =   2595
  26.       TabIndex        =   9
  27.       Top             =   1800
  28.       Width           =   2655
  29.    End
  30.    Begin VB.CommandButton cmdShow 
  31.       Caption         =   "Show Mileage between Origin and Destination"
  32.       Height          =   495
  33.       Left            =   120
  34.       TabIndex        =   8
  35.       Top             =   1200
  36.       Width           =   4095
  37.    End
  38.    Begin VB.TextBox txtDest 
  39.       Height          =   285
  40.       Left            =   3360
  41.       TabIndex        =   7
  42.       Top             =   720
  43.       Width           =   375
  44.    End
  45.    Begin VB.TextBox txtOrig 
  46.       Height          =   285
  47.       Left            =   3360
  48.       TabIndex        =   5
  49.       Top             =   360
  50.       Width           =   375
  51.    End
  52.    Begin VB.Label lblPh 
  53.       Caption         =   "4. Philadelphia"
  54.       Height          =   255
  55.       Left            =   360
  56.       TabIndex        =   3
  57.       Top             =   840
  58.       Width           =   1335
  59.    End
  60.    Begin VB.Label lblNY 
  61.       Caption         =   "3. New York"
  62.       Height          =   255
  63.       Left            =   360
  64.       TabIndex        =   2
  65.       Top             =   600
  66.       Width           =   1335
  67.    End
  68.    Begin VB.Label lblLA 
  69.       Caption         =   "2. Los Angeles"
  70.       Height          =   255
  71.       Left            =   360
  72.       TabIndex        =   1
  73.       Top             =   360
  74.       Width           =   1335
  75.    End
  76.    Begin VB.Label lblCh 
  77.       Caption         =   "1. Chicago"
  78.       Height          =   255
  79.       Left            =   360
  80.       TabIndex        =   0
  81.       Top             =   120
  82.       Width           =   1335
  83.    End
  84.    Begin VB.Label lblDest 
  85.       Alignment       =   1  'Right Justify
  86.       Caption         =   "Destination"
  87.       Height          =   255
  88.       Left            =   2160
  89.       TabIndex        =   6
  90.       Top             =   720
  91.       Width           =   1095
  92.    End
  93.    Begin VB.Label lblOrig 
  94.       Alignment       =   1  'Right Justify
  95.       Caption         =   "Origin"
  96.       Height          =   255
  97.       Left            =   2160
  98.       TabIndex        =   4
  99.       Top             =   360
  100.       Width           =   1095
  101.    End
  102. Attribute VB_Name = "frmDist"
  103. Attribute VB_GlobalNameSpace = False
  104. Attribute VB_Creatable = False
  105. Attribute VB_PredeclaredId = True
  106. Attribute VB_Exposed = False
  107. Dim rm(1 To 4, 1 To 4) As Single
  108. Private Sub cmdShow_Click()
  109.   Dim row As Integer, col As Integer
  110.   'Determine road mileage between cities
  111.   row = Val(txtOrig.Text)
  112.   col = Val(txtDest.Text)
  113.   If (row >= 1 And row <= 4) And (col >= 1 And col <= 4) Then
  114.       Call ShowMileage(rm(), row, col)
  115.     Else
  116.       MsgBox "Origin and Destination must be numbers from 1 to 4", , "Error"
  117.   End If
  118.   txtOrig.SetFocus
  119. End Sub
  120. Private Sub Form_Load()
  121.   Dim row As Integer, col As Integer
  122.   'Fill two-dimensional array with intercity mileages
  123.   'Assume the data has been placed in the file "DISTANCE.TXT"
  124.   '(First line of the file is 0, 2054, 802, 738)
  125.   Open App.Path & "\DISTANCE.TXT" For Input As #1
  126.   For row = 1 To 4
  127.     For col = 1 To 4
  128.       Input #1, rm(row, col)
  129.     Next col
  130.   Next row
  131.   Close #1
  132. End Sub
  133. Private Sub ShowMileage(rm() As Single, row As Integer, col As Integer)
  134.   'Display mileage between cities
  135.   picMiles.Cls
  136.   picMiles.Print "The road mileage is"; rm(row, col)
  137. End Sub
  138.