Alex Alex - 1 year ago 75 Question

Write to new lines of sequential file in Visual Basic 2010

Okay, so, I'm supposed to be able to access a file that already has values in it and write values to that file (namely questions).

This is my code so far:

Private Sub AddQuestion(sender As System.Object, e As System.EventArgs) Handles btnQuestions.Click
Dim pass, response, question As String
pass = "sample01"
response = InputBox("Please enter the administrator password.", "Password")
If response = pass Then
FileOpen(1, "W:\Visual Studio 2010\Projects\Culminating\assets\questions.txt", OpenMode.Output)
question = InputBox("Enter new question.", "New Question")
If question = String.Empty Then
Exit Do
End If
Write(1, question)
Else : MsgBox("Incorrect password. Please enter again.", MsgBoxStyle.Critical, "Incorrect Password")
End If
End Sub

This adds the questions to my file, however, if I exit out of the input box and try again, it will overwrite the old questions with the new ones.

Answer Source
FileOpen(1, "W:\Visual Studio 2010\Projects\Culminating\assets\questions.txt", OpenMode.Output)

OpenMode.Output opens the file for overwriting the contents. You want OpenMode.Append.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download