常常程式碼內有許多空行,本來就很長了,加上空行就變更長了,這時就需要把那些無用的空行刪除了。
Private Sub DelSpace_Click()
Open App.Path & "\log.txt" For Output As #1 '存到\log.txt
Print #1, TxtMain 'strsql是變數名稱
Close #1
Dim a, i
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
If Len(Trim(List1.Text)) > 0 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