I am trying to determine whether the names.txt file exists and if it does, the procedure should show the MessageBox.show method to ask if they want to replace the existing file. Well, I keep getting the dialog box that the file doesnt exist - but it does exist. Also, I am not sure if I have the procedure in the correct order, the ' write name to the txt file code is the part where I am not sure where this should be placed. I need to be able to write two names to the names.txt file.
I am including a copy of my code, in case anybody can help with this.
Private Sub writeButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles writeButton.Click
Dim file As String = "C:\Documents and Settings\Owner\My Documents\Modified Employee List Solution\Employee List Project\bin\Debug\names.txt\"
Dim name As String
Dim text As String
Dim button As DialogResult
' write name file to txt file
name = nameTextBox.Text
My.Computer.FileSystem.WriteAllText(file, _
name, True)
My.Computer.FileSystem.WriteAllText(file, ControlChars.NewLine & ControlChars.NewLine, True)
' check for names.txt file
If My.Computer.FileSystem.FileExists(file & "names.txt") Then
text = My.Computer.FileSystem.ReadAllText(file & "names.txt")
Else
MessageBox.Show("File does not exist", "Names", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
If My.Computer.FileSystem.FileExists(file & "names.txt") Then
button = MessageBox.Show("Erase the file?", _
"Information", MessageBoxButtons.YesNo, _
MessageBoxIcon.Exclamation, _
MessageBoxDefaultButton.Button2)
If button = DialogResult.Yes Then
My.Computer.FileSystem.WriteAllText(file & "names.txt", _
String.Empty, False)
End If
End If
End Sub

New Topic/Question
Reply




MultiQuote




|