2013-04-22 80 views
1

我需要知道如何從我的Visual Basic 2010程序中保存.txt文件並將其保存爲特殊格式。將.txt文件保存爲特殊格式

我需要它來保存像"monday:[email protected]" & "4/22/2013:[email protected]".

我將如何做到這一點?

我使用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 

回答

0

那是哪裏週一和[email protected]從?取決於你想要的,調整變量strFileName accrodingly,說當前日期,當前日期,動態電子郵件地址從數據庫拉,等等;否則,這將做

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

strFileName = "monday:[email protected]" & "4/22/2013:[email protected]" & ".txt" 
strContent = "whatever you want" 

My.Computer.FileSystem.WriteAllText(strFileName, strContent, True)