继续请教版主和其他前辈高人:
读TXT文件,判断什么的,目前看起来没什么问题,也能确定要删除的行号(起止行号都能确定下来),但现在问题是,如何删除这些行,我写的删除这段程序似乎有问题,达不到预期目的,请帮看一看并帮助修改。
附件为源程序和实验文本。下面飘红的那段有问题。
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Label2.Caption = Dir1.Path & "\" & File1.FileName
Dim a As Long
Dim yjg As String
Dim cpm As String
a = 0
Open (Dir1.Path & "\" & File1.FileName) For Input As #1
Do Until EOF(1)
Line Input #1, yjg
For i = 1 To Len(yjg)
If Mid$(yjg, i, 1) = "#" Then
a = a + 1
End If
Next i
Loop
Close #1
Label4.Caption = "共有" & a & "个的数据"
End Sub
Private Sub Command2_Click()
Dim h As Long, LTxt As String, wjt As Variant, wjw As Variant, binz As Variant, MaxDate As Date, FindLine As Long, bin() As Byte
Dim temp
h = FreeFile
Dim N As Long, m As Long, o As Long
Open (Dir1.Path & "\" & File1.FileName) For Input As h
Do While Not EOF(h)
Line Input #h, LTxt
N = N + 1 '对应Device#
Dim wjt
o = o + 1 '对应Bin
Dim binz
'
m = m + 1 '对应==========
Dim wjw
wjt = Split(LTxt, "Device#:")
binz = Split(LTxt, " Site
Sort
Bin")
'
wjw = Split(LTxt, "=========================================================================")
If UBound(wjt) = 1 Then
'
MsgBox "Device#:在" & n & " 行"
Text1.Text = N
End If
If UBound(binz) = 1 Then
'
MsgBox " Site
Sort
Bin在" & o + 2 & " 行"
Text3.Text = o + 3
'MsgBox " "========================================================================="在" & o + 3 & " 行"
Text2.Text = o + 2
'MsgBox " Site
Sort
Bin在" & o + 2 & " 行"
Text5.Text = Val(Text3.Text) - Val(Text1.Text) + 1
End If
If o = Val(Text2.Text) Then
temp = Split(LTxt, "
")
Text4.Text = temp(5)
End If
If Val(Text4.Text) > 1 And Val(Text3.Text) = Val(Text2.Text) + 1 And Val(Text3.Text) > Val(Text1.Text) Then
MsgBox "从" & Val(Text1.Text) & "行到" & Val(Text3.Text) & "行由于Bin值为" & Val(Text4.Text) & ",这段行数可以被删除,共" & Val(Text5.Text) & "行。"
Close
Dim arr, c As Long, d As Long
For m = Val(Text3.Text) To Val(Text1.Text) '想倒着删,正着删的话,删掉一行部件参数尾部的行数就发生了变化。
Open (Dir1.Path & "\" & File1.FileName) For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
N = m '删除第2行
Open "c:\123.txt" For Output As #1
For c = 0 To UBound(arr)
If c <> d - 1 Then Print #1, arr(c)
Next
Close #1
m = m - 1
Next m
Open (Dir1.Path & "\" & File1.FileName) For Input As h
End If
Loop
Close
MsgBox "结束"
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_DblClick()
Call Command1_Click
End Sub
[此贴子已经被作者于2017-4-2 16:25编辑过]