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 / CH8 / 8-1-2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-16  |  4.9 KB  |  168 lines

  1. VERSION 5.00
  2. Begin VB.Form frm8_1_2 
  3.    Caption         =   "Access YOB.TXT"
  4.    ClientHeight    =   2910
  5.    ClientLeft      =   1305
  6.    ClientTop       =   1605
  7.    ClientWidth     =   3000
  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     =   2910
  20.    ScaleWidth      =   3000
  21.    Begin VB.CommandButton cmdDelete 
  22.       Caption         =   "Delete Above Person from File"
  23.       Height          =   495
  24.       Left            =   120
  25.       TabIndex        =   6
  26.       Top             =   2280
  27.       Width           =   2775
  28.    End
  29.    Begin VB.CommandButton cmdLookup 
  30.       Caption         =   "Look up Year of Birth"
  31.       Height          =   495
  32.       Left            =   120
  33.       TabIndex        =   5
  34.       Top             =   1680
  35.       Width           =   2775
  36.    End
  37.    Begin VB.CommandButton cmdAdd 
  38.       Caption         =   "Add Above Person to File"
  39.       Height          =   495
  40.       Left            =   120
  41.       TabIndex        =   4
  42.       Top             =   1080
  43.       Width           =   2775
  44.    End
  45.    Begin VB.TextBox txtYOB 
  46.       Height          =   285
  47.       Left            =   1320
  48.       TabIndex        =   3
  49.       Top             =   600
  50.       Width           =   1095
  51.    End
  52.    Begin VB.TextBox txtName 
  53.       Height          =   285
  54.       Left            =   720
  55.       TabIndex        =   1
  56.       Top             =   120
  57.       Width           =   1695
  58.    End
  59.    Begin VB.Label lblYOB 
  60.       Caption         =   "Year of Birth"
  61.       Height          =   255
  62.       Left            =   120
  63.       TabIndex        =   2
  64.       Top             =   600
  65.       Width           =   1095
  66.    End
  67.    Begin VB.Label lblNamr 
  68.       Caption         =   "Name"
  69.       Height          =   255
  70.       Left            =   120
  71.       TabIndex        =   0
  72.       Top             =   120
  73.       Width           =   615
  74.    End
  75. Attribute VB_Name = "frm8_1_2"
  76. Attribute VB_GlobalNameSpace = False
  77. Attribute VB_Creatable = False
  78. Attribute VB_PredeclaredId = True
  79. Attribute VB_Exposed = False
  80. Private Sub cmdAdd_Click()
  81.   Dim message As String
  82.   'Add a person's name and year of birth to file
  83.   If (txtName.Text <> "") And (txtYOB.Text <> "") Then
  84.       Open App.Path & "\YOB.TXT" For Append As #1
  85.       Write #1, txtName.Text, Val(txtYOB.Text)
  86.       Close #1
  87.       txtName.Text = ""
  88.       txtYOB.Text = ""
  89.       txtName.SetFocus
  90.     Else
  91.       message = "You must enter a name and year of birth."
  92.       MsgBox message, , "Information Incomplete"
  93.   End If
  94. End Sub
  95. Private Sub cmdLookUp_Click()
  96.   Dim message As String
  97.   'Determine a person's year of birth
  98.   If txtName.Text <> "" Then
  99.       If Dir(App.Path & "\YOB.TXT") <> "" Then
  100.           Call DisplayYearOfBirth
  101.         Else
  102.           message = "Either no file has yet been created or "
  103.           message = message & "the file is not where expected."
  104.           MsgBox message, , "File Not Found"
  105.       End If
  106.     Else
  107.       MsgBox "You must enter a name.", , "Information Incomplete"
  108.   End If
  109.   txtName.SetFocus
  110. End Sub
  111. Private Sub cmdDelete_Click()
  112.   Dim message As String
  113.   'Remove a person from the file
  114.   If txtName.Text <> "" Then
  115.       If Dir(App.Path & "\YOB.TXT") <> "" Then
  116.           Call DeletePerson
  117.         Else
  118.           message = "Either no file has yet been created or "
  119.           message = message & "the file is not where expected."
  120.           MsgBox message, , "File Not Found."
  121.       End If
  122.     Else
  123.       MsgBox "You must enter a name.", , "Information Incomplete"
  124.   End If
  125.   txtName.SetFocus
  126. End Sub
  127. Private Sub DeletePerson()
  128.   Dim nom As String, yob As Integer, foundFlag As Boolean
  129.   foundFlag = False
  130.   Open App.Path & "\YOB.TXT" For Input As #1
  131.   Open App.Path & "\TEMP" For Output As #2
  132.   Do While Not EOF(1)
  133.     Input #1, nom, yob
  134.     If nom <> txtName.Text Then
  135.         Write #2, nom, yob
  136.       Else
  137.         foundFlag = True
  138.     End If
  139.   Loop
  140.   Close #1
  141.   Close #2
  142.   Kill App.Path & "\YOB.TXT"
  143.   Name App.Path & "\TEMP" As App.Path & "\YOB.TXT"
  144.   If Not foundFlag Then
  145.       MsgBox "The name was not found.", , ""
  146.     Else
  147.       txtName.Text = ""
  148.       txtYOB.Text = ""
  149.   End If
  150. End Sub
  151. Private Sub DisplayYearOfBirth()
  152.   Dim nom As String, yob As Integer
  153.   'Find the year of birth for the name in txtName
  154.   txtYOB.Text = ""
  155.   Open App.Path & "\YOB.TXT" For Input As #1
  156.   nom = ""
  157.   Do While (nom <> txtName.Text) And (Not EOF(1))
  158.     Input #1, nom, yob
  159.   Loop
  160.   If nom = txtName.Text Then
  161.       txtYOB.Text = Str(yob)
  162.     Else
  163.       MsgBox "Person is not in file.", , ""
  164.       txtName.Text = ""
  165.   End If
  166.   Close #1
  167. End Sub
  168.