2017-01-27 14 views
0

テキストファイル内の行を削除すると問題が発生します。ここに私のコードです。私を助けてくれてありがとう。テキストファイル内の行を削除した後に空白を削除するVB6

iFileList = FreeFile 
iFileList2 = FreeFile 

Open App.Path & "\months\" & gMonth & ".txt" For Input As #iFileList 

Do While Not EOF(iFileList) 
    Line Input #iFileList, sLine 
    tempHolder2 = Split(sLine, "/") 
    If Len(sLine) > 0 Then 
     If gDay = tempHolder2(0) Then 
      If tempHolder2(1) Like lvAlarm.selectedItem Then 
       'skip the line 
      Else 
       sNewText = sNewText & sLine & vbCrLf 
      End If 
     End If 
    End If 

Loop 
Close 
Debug.Print (sNewText) 
iFile = FreeFile 
Open App.Path & "\months\" & gMonth & ".txt" For Output As #iFile 
'sNewText = sNewText & vbCrLf 
Print #iFile, Trim(sNewText) 
Close 

答えて

2

あなたが参照している空白スペースは、ファイルの最後にあり、他のラインに散在していないと思われます。その場合は、sNewText変数の内容をファイルに出力するときに使用するTrimコマンドが、文字列の末尾にある最後の改行/改行のペアを削除しないためです。

If Right$(sNewText,2) = vbCrLf Then 
    sNewText = Left$(sNewText, Len(sNewText) - 2) 
End If 

は、末尾の改行を削除するには、おそらく次の操作を行う必要があります
関連する問題