1

我需要知道如何能够.txt从我的Visual Basic 2010程序中保存文件并将其保存为特殊格式。

我需要它来保存"monday:email@email.com" & "4/22/2013:email@email.com".

我该怎么做?

我正在使用 Visual Basic 2010。

还有 2 个列表框也需要像这样保存。"listbox1info:listbox2info".

我需要更新我的程序ASAP

如何实现这一目标?

我的代码是:

Public Class Form1
    Dim streamer As IO.StreamReader

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OpenFileDialog1.ShowDialog()
        ListBox1.Text = OpenFileDialog1.FileName
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        streamer = IO.File.OpenText(ListBox1.Text)
        Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine)
        ListBox1.Items.AddRange(mystring)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        OpenFileDialog1.ShowDialog()
        TextBox2.Text = OpenFileDialog1.FileName
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        streamer = IO.File.OpenText(TextBox2.Text)
        Dim mystring() As String = streamer.ReadToEnd.Split(vbNewLine)
        ListBox2.Items.AddRange(mystring)
    End Sub
End Class
4

1 回答 1

0

那个星期一和 email@email.com 来自哪里?取决于你想要什么,相应地调整变量strFileName,比如当天,当前日期,从数据库中提取的动态电子邮件地址等;否则,这会做

Dim strFileName As String = ""
Dim strContent As String = ""

strFileName = "monday:email@email.com" & "4/22/2013:email@email.com" & ".txt"
strContent = "whatever you want"

My.Computer.FileSystem.WriteAllText(strFileName, strContent, True)
于 2013-04-23T10:06:32.007 回答