上篇說開頭,這篇就說結尾了
Private Sub EndAddString_Click()
Open App.Path & "\log.txt" For Output As #1 '存到c:\log.txt
Print #1, TxtMain 'strsql是變數名稱
Close #1
Dim a, i, StrWord
StrWord = InputBox("請輸入結尾要加入的字串", "請輸結尾入字串")
Open App.Path & "\log.txt" For Input As #1 '載入 檔案before.txt
While Not EOF(1)
Line Input #1, a
List1.AddItem a '增加list1.additem
Wend
Close #1
Open App.Path & "\log.txt" For Output As #2 '存到c:\log.txt
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
' Print #2, List1.Text
'If Len(List1.Text) > 0 Then Print #2, Mid(List1.Text, 1, Len(List1.Text) - intN)
If Len(List1.Text) > 0 Then Print #2, List1.Text + StrWord
If List1.Text = "" Then Print #2, List1.Text
Next
Close #2
Open App.Path & "\log.txt" For Input As #1 '重新載入 檔案log.txt
TxtMain.Text = ""
List1.Clear
While Not EOF(1)
Line Input #1, a
TxtMain = TxtMain + a + vbCrLf '增加list1.additem
Wend
Close #1
End Sub