也是很常用 功能,如果每行後面都有句點要移除,也用的到這個功能。
Private Sub dellast_Click()
Open App.Path & "\log.txt" For Output As #1 '存到\log.txt
Print #1, TxtMain 'strsql是變數名稱
Close #1
Dim a, i, intN
intN = InputBox("請輸入 n 的值", "請輸入 n 的值", 1)
Open App.Path & "\log.txt" For Input As #1 '載入 log.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 '存到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 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