30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

826 Files and Streams Chapter 17<br />

41 ' invoked when user clicks Delete Record but<strong>to</strong>n<br />

42 Protected Sub cmdDelete_Click(ByVal sender As System.Object, _<br />

43 ByVal e As System.EventArgs) Handles cmdDelete.Click<br />

44<br />

45 Dim record As CRandomAccessRecord = _<br />

46 transactionProxy.GetRecord(txtAccount.Text)<br />

47<br />

48 ' if record exists, delete it in file<br />

49 If (record Is Nothing) = False Then<br />

50 DeleteRecord(record)<br />

51 End If<br />

52<br />

53 Me.Hide()<br />

54 showPreviousWindow()<br />

55 End Sub ' cmdDelete_Click<br />

56<br />

57 ' invoked when user clicks Cancel but<strong>to</strong>n<br />

58 Protected Sub cmdCancel_Click(ByVal sender As System.Object, _<br />

59 ByVal e As System.EventArgs) Handles cmdCancel.Click<br />

60<br />

61 Me.Hide()<br />

62 showPreviousWindow()<br />

63 End Sub ' cmdCancel_Click<br />

64<br />

65 ' delete record in file at position specified by accountNumber<br />

66 Public Sub DeleteRecord(ByVal record As CRandomAccessRecord)<br />

67<br />

68 Dim accountNumber As Integer = record.Account<br />

69<br />

70 ' display error message if record does not exist<br />

71 If record.Account = 0 Then<br />

72 MessageBox.Show("Record Does Not Exist", "Error", _<br />

73 MessageBoxBut<strong>to</strong>ns.OK, MessageBoxIcon.Error)<br />

74 txtAccount.Clear()<br />

75<br />

76 Return<br />

77 End If<br />

78<br />

79 ' create blank record<br />

80 record = New CRandomAccessRecord()<br />

81<br />

82 ' write over file record with empty record<br />

83 If (transactionProxy.AddRecord( _<br />

84 record, accountNumber) = True) Then<br />

85<br />

86 ' notify user of successful deletion<br />

87 MessageBox.Show("Record Deleted", "Success", _<br />

88 MessageBoxBut<strong>to</strong>ns.OK, MessageBoxIcon.Information)<br />

89 Else<br />

90<br />

91 ' notify user of failure<br />

92 MessageBox.Show("Record could not be deleted", "Error", _<br />

Fig. 17.23 FrmDeleteDialog class enables users <strong>to</strong> remove records from files in<br />

transaction-processor case study (part 2 of 3).

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

Saved successfully!

Ooh no, something went wrong!