【问题标题】:How to append text pending on checkbox state?如何在复选框状态下附加待处理的文本?
【发布时间】:2010-11-15 17:50:29
【问题描述】:

我正在制作一个带有复选框的表单,如果选中,目标文件将附加 text-A,如果未选中,则文件将附加 text-B

我该怎么做?

到目前为止我有什么:

    Private Sub CheckBox1_Checked(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.Checked
    Dim FILE_NAME As String = "C:\ANSWERSLIST.txt"

    'Adding items for AutoCAD 2006...
    If System.IO.File.Exists(FILE_NAME) = True Then
        Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
        objWriter.WriteLine("YES")
        objWriter.Close()
    End If
End Sub

【问题讨论】:

    标签: vb.net checkbox append state text-files


    【解决方案1】:

    您可以使用AppendAllText 方法:

    If MyCheckBox.IsChecked Then
        File.AppendAllText("foo.txt", "text-A")
    Else
        File.AppendAllText("foo.txt", "text-B")
    End If
    

    【讨论】:

    • 文件声明为什么?
    • 这可能有点奇怪,但我是 VB.net 的新手,现在我的 VB.net 说名称“文件”未声明?
    • @rick,你可能需要在你的模块中import System.IO
    • 我可以正常使用任何其他 System.IO 函数,这可能是我自己的编码出错了
    猜你喜欢
    • 2019-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2013-07-23
    • 2019-10-25
    • 2018-04-08
    • 2019-05-26
    相关资源
    最近更新 更多