![]() |
#2
xzlxzlxzl2017-04-07 20:44
|
@123
-1
-5
-10
@234
-2
-4
@345
-3
-8
经程序处理后(程序的目的是我输入一个数字,如果数字为@后面的字符串就删除@那行和下个@之前的那些行。比如我输入“234”,理想的输出文本内容应为:
@123
-1
-5
-10
@345
-3
-8
但实际输出文本的内容如下,每行前面的空格没有了:
@123
-1
-5
-10
@345
-3
-8
请问程序中哪里需要修改?
附程序:
在窗体中添加下列代码并画上按钮控件command1和text1

Private Sub Command1_Click()
Dim FileRead As Integer
Dim FileWrite As Integer
Dim Str As String
Dim flag1, flag2 As Boolean
flag1 = False
flag2 = False
FileRead = FreeFile
If Dir(App.Path & "\" & "testfile.txt") <> "" Then
Open App.Path & "\" & "testfile.txt" For Input As FileRead
FileWrite = FreeFile
Open App.Path & "\" & "Tmp.txt" For Output As FileWrite
Do While Not EOF(FileRead)
If flag1 = False Then
Input #FileRead, Str
If InStr(Str, "@" & Text1.Text) <> 0 Then
flag1 = True
flag2 = False
Else
Print #FileWrite, Str
End If
Else
Input #FileRead, Str
If InStr(Str, "@") <> 0 And InStr(Str, "@" & Text1.Text) = 0 Then
flag2 = True
ElseIf InStr(Str, "@" & Text1.Text) <> 0 Then
flag1 = True
flag2 = False
End If
If flag2 = True Then
Print #FileWrite, Str
End If
End If
Loop
Close FileRead
Close FileWrite
Kill App.Path & "\" & "testfile.txt"
Name App.Path & "\" & "Tmp.txt" As App.Path & "\" & "testfile.txt"
Else
MsgBox "文件不存在!"
End If
End Sub
[此贴子已经被作者于2017-4-7 12:47编辑过]