嘿我正在尝试使用表格将一些数据写入失败。 我得到它的工作,但每次我添加一个新的数据时,最后一段数据被覆盖,导致文件保持2行。
每次单击Button1时,我都希望它将所有以前捕获的数据发送到文件。
My.Computer.FileSystem.WriteAllText("C:\Users\Michael\Documents\University\Application Programming\Assignment\Logs\AuditLog.htm", "<table border=1 width=100%> <tr><td> Staff Name </td> <td> Computer Number </td> <td> Fault </td> <td> Assigned Technician </td> <td> Date Submitted </td> </tr> ", False)
My.Computer.FileSystem.WriteAllText("C:\Users\Michael\Documents\University\Application Programming\Assignment\Logs\AuditLog.htm", "<tr> <td> <b> </b>" & StaffName & "</td> <td>" & ComputerNumber & "</td> <td>" & Fault & "</td> <td> " & AssignedTechnician & "</td> <td> " & DateSub & "</tr>", True)
这就是我的问题所在。我想我在第二行需要一种for循环。但不确定如何去做。
任何帮助表示赞赏。感谢。
答案 0 :(得分:1)
看看这段代码
Dim FILE_NAME As String = "C:\Users\Owner\Documents\test.txt"
Dim i As Integer
Dim aryText(4) As String
aryText(0) = "Mary WriteLine"
aryText(1) = "Had"
aryText(2) = "Another"
aryText(3) = "Little"
aryText(4) = "One"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
For i = 0 To 4
objWriter.WriteLine(aryText(i))
Next
objWriter.Close()
MsgBox("Text Appended to the File")