Private Sub cmdsummary_Click(sender As Object, e As EventArgs) Handles cmdsummary.Click
Dim writer As New System.IO.StreamWriter("C:\Users\salman\Desktop\Text.txt")
writer.WriteLine(Me.customer.Text + Me.txtcustomer.Text)
writer.WriteLine(Me.todaystotal.Text + Me.txtsummarytotal.Text)
writer.WriteLine(Me.average.Text + Me.txtaveragetotal.Text)
writer.Close()
End Sub
每次点击cmdsummary它都会编辑记事本文件(txt)并更新它,但我想在每次单击此按钮时创建一个新的txt文件。
答案 0 :(得分:0)
我认为您每次都必须更改文本文件或文件路径的名称,否则它将继续写入相同的位置(和相同的文件)。
编辑:带简单计数器的代码
Dim filesWritten as Integer = 0
Private Sub cmdsummary_Click(sender As Object, e As EventArgs) Handles cmdsummary.Click
Dim writer As New System.IO.StreamWriter("C:\Users\salman\Desktop\Text" & filesWritten & ".txt")
writer.WriteLine(Me.customer.Text + Me.txtcustomer.Text)
writer.WriteLine(Me.todaystotal.Text + Me.txtsummarytotal.Text)
writer.WriteLine(Me.average.Text + Me.txtaveragetotal.Text)
writer.Close()
filesWritten+=1
End Sub