CommonDialog1.Filter = "*.txt 文件|*.txt" CommonDialog1.ShowOpen Open CommonDialog1.FileName For Input As #1 Dim i As Integer Dim Tx As String Tx = "" i = 0 Do While Not EOF(1) ' 循环至文件尾。 i = i + 1 If i < 4 Then Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。 Tx = Tx & TextLine & vbCrLf Else Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。 Tx = Tx & Replace(TextLine, " ", "") & vbCrLf End If Loop Close #1 Open CommonDialog1.FileName For Output As #1 Print #1, Tx Close #1
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Dim i As Integer
Dim Tx As String
Tx = ""
i = 0
Do While Not EOF(1) ' 循环至文件尾。
i = i + 1
If i < 4 Then
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Tx = Tx & TextLine & vbCrLf
Else
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Tx = Tx & Replace(TextLine, " ", "") & vbCrLf
End If
Loop
Close #1
Open CommonDialog1.FileName For Output As #1
Print #1, Tx
Close #1