I am trying to check to make sure my program doesn't blow up when trying to retrieve data from a txt file.
I have two options on my address book screen.... Save and Get.
I want to show an error if they click get before there is anything saved in the text file.
I have the following for button clicks to save and retrieve the data.
I have two options on my address book screen.... Save and Get.
I want to show an error if they click get before there is anything saved in the text file.
I have the following for button clicks to save and retrieve the data.
' When clicking the save button on the form, the information will save to pim.txt.
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Using fp As New IO.StreamWriter("PIM.txt")
fp.WriteLine(txtName.Text)
fp.WriteLine(cboSuffix.SelectedItem)
fp.WriteLine(cboMonth.SelectedItem)
fp.WriteLine(cboDay.SelectedItem)
fp.WriteLine(txtYear.Text)
fp.WriteLine(txtAddress.Text)
fp.WriteLine(txtCity.Text)
fp.WriteLine(txtState.Text)
fp.WriteLine(txtZip.Text)
fp.WriteLine(MaskedtxtPhone.Text)
fp.WriteLine(txtCompany.Text)
fp.Close()
End Using
End Sub
' When clicking the get button on the form, the information saved in the pim.txt file will be loaded into the fields.
Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
Using fp As New IO.StreamReader("PIM.txt")
txtName.Text = fp.ReadLine
cboSuffix.SelectedItem = fp.ReadLine
cboMonth.SelectedItem = fp.ReadLine
cboDay.SelectedItem = fp.ReadLine
txtYear.Text = fp.ReadLine
txtAddress.Text = fp.ReadLine
txtCity.Text = fp.ReadLine
txtState.Text = fp.ReadLine
txtZip.Text = fp.ReadLine
MaskedtxtPhone.Text = fp.ReadLine
txtCompany.Text = fp.ReadLine
fp.Close()
End Using
End Sub