
VB删除重复行时把空行也一并删除了。。。。
我的代码如下:Open"a.txt"ForInputAs#1Open"b.txt"ForOutputAs#2DimSAsStringDimCAsNewCollection...
我的代码如下:
Open "a.txt" For Input As #1
Open "b.txt" For Output As #2
Dim S As String
Dim C As New Collection
Dim V As Variant
On Error Resume Next
Do Until EOF(1)
Input #1, S
Call C.Add(S, S)
Loop
For Each V In C
Print #2, V
Next
Close #1, #2
每次运行时可以把重复的行删除掉,但是空行也一并删掉了。。。。
空行是为了便于阅读而加入的,怎么才能让它不删除空行呢?
谢谢各位了。 展开
Open "a.txt" For Input As #1
Open "b.txt" For Output As #2
Dim S As String
Dim C As New Collection
Dim V As Variant
On Error Resume Next
Do Until EOF(1)
Input #1, S
Call C.Add(S, S)
Loop
For Each V In C
Print #2, V
Next
Close #1, #2
每次运行时可以把重复的行删除掉,但是空行也一并删掉了。。。。
空行是为了便于阅读而加入的,怎么才能让它不删除空行呢?
谢谢各位了。 展开
展开全部
这样试一试
我测试通过
Private Sub Form_Load()
Open App.Path & "\a.txt" For Input As #1
Open App.Path & "\b.txt" For Output As #2
Dim S As String
Dim C As New Collection
Dim V As Variant
On Error Resume Next
i = 0
Do Until EOF(1)
Input #1, S
If Trim(S) = "" Then
Call C.Add(S, S & i)
i = i + 1
Else
Call C.Add(S, S)
End If
Loop
For Each V In C
Print #2, V
Next
Close #1, #2
End Sub
我测试通过
Private Sub Form_Load()
Open App.Path & "\a.txt" For Input As #1
Open App.Path & "\b.txt" For Output As #2
Dim S As String
Dim C As New Collection
Dim V As Variant
On Error Resume Next
i = 0
Do Until EOF(1)
Input #1, S
If Trim(S) = "" Then
Call C.Add(S, S & i)
i = i + 1
Else
Call C.Add(S, S)
End If
Loop
For Each V In C
Print #2, V
Next
Close #1, #2
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询