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

时间:2016-06-10 15:52:06

标签: vb.net file-writing

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

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

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

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

1 个答案:

答案 0 :(得分:2)

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

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