写入 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 2010ProjectsCulminatingassetsquestions.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 2010ProjectsCulminatingassetsquestions.txt", OpenMode.Output)

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