在 Visual Basic 2010 中写入新的顺序文件行

Write to new lines of sequential file in Visual Basic 2010

好的,所以,我应该能够访问其中已有值的文件并将值写入该文件(即问题)。

到目前为止,这是我的代码:

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)
        Do
            question = InputBox("Enter new question.", "New Question")
            If question = String.Empty Then
                Exit Do
            End If
            Write(1, question)
            WriteLine(1)
        Loop
        FileClose(1)
    Else : MsgBox("Incorrect password. Please enter again.", MsgBoxStyle.Critical, "Incorrect Password")
    End If
End Sub

这会将问题添加到我的文件中,但是,如果我退出输入框并重试,它将用新问题覆盖旧问题。

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

OpenMode.Output 打开文件覆盖内容。你想要 OpenMode.Append.