I am familiar with two ways of writing to a text file so the data persists when you access it again. Adding more data (from textbox and label) will be necessary for future transactions. I'd like to learn how to write the code so I don't get an UnauthorizedAcc essException class.
I am using this way, resulting in error:
And there is this way (with errors again):
I'm sure there is something I am not quite getting. Some guidance would be appreciated.
I am using this way, resulting in error:
Code:
Dim objwriter As New System.IO.StreamWriter("C:\Customer Transactions.txt")
objwriter.Write(txtCustName.Text, lblOrderNo, lblFinalCost)
objwriter.Close()
And there is this way (with errors again):
Code:
Dim myStream As Stream
Dim saveFileDialg As New SaveFileDialog()
saveFileDialg.Filter = ("C:\Customer Transactions.txt")
saveFileDialg.FilterIndex = 2
saveFileDialg.RestoreDirectory = True
If saveFileDialg.ShowDialog() = DialogResult.OK Then
myStream = saveFileDialg.OpenFile()
If (myStream IsNot Nothing) Then
myStream.WriteLine(txtFullName.Text, lblOrder, lblTotal)
myStream.Close()
myStream.Close()
End If
End If
I'm sure there is something I am not quite getting. Some guidance would be appreciated.
Comment