19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

220 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

‘Add a person’s name <strong>and</strong> year of birth to file<br />

If (txtName.Text “”) And (txtYOB.Text “”) Then<br />

Open “YOB.TXT” For Append As #1<br />

Write #1, txtName.Text, Val(txtYOB.Text)<br />

Close #1<br />

txtName.Text = “”<br />

txtYOB.Text = “”<br />

txtName.SetFocus<br />

Else<br />

message = “You must enter a name <strong>and</strong> year of birth.”<br />

MsgBox message, , “Information Incomplete”<br />

End If<br />

End Sub<br />

Private Sub cmdLookUp_Click()<br />

Dim message As String<br />

‘Determine a person’s year of birth<br />

If txtName.Text “” Then<br />

If Dir(“YOB.TXT”) “” Then<br />

Call DisplayYearOfBirth<br />

Else<br />

message = “Either no file has yet been created or ”<br />

message = message & “the file is not where expected.”<br />

MsgBox message, , “File Not Found”<br />

End If<br />

Else<br />

MsgBox “You must enter a name.”, , “Information Incomplete”<br />

End If<br />

txtName.SetFocus<br />

End Sub<br />

Private Sub cmdDelete_Click()<br />

Dim message As String<br />

‘Remove a person from the file<br />

If txtName.Text “” Then<br />

If Dir(“YOB.TXT”) “” Then<br />

Call DeletePerson<br />

Else<br />

message = “Either no file has yet been created or ”<br />

message = message & “the file is not where expected.”<br />

MsgBox message, , “File Not Found.”<br />

End If<br />

Else<br />

MsgBox “You must enter a name.”, , “Information Incomplete”<br />

End If<br />

txtName.SetFocus<br />

End Sub<br />

Private Sub DeletePerson()<br />

Dim nom As String, yob As Integer, foundFlag As Boolean<br />

foundFlag = False Open “YOB.TXT” For Input As #1<br />

Open “TEMP” For Output As #2<br />

Do While Not EOF(1)<br />

Input #1, nom, yob<br />

If nom txtName.Text Then

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!