跪求VB读文本问题,急急急

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:40:17
一个文本文件如下:
1 2961889.931 37651615.31

2 2961889.964 37651615.05

3 2961874.201 37651602.49

4 2961856.739 37651592.93
.....
想通过VB将它转为
1
2961889.931
37651615.31
2
2961889.964
37651615.05
3
2961874.201
37651602.49
4
2961856.739
37651592.93
.....
希望能给详细代码说明,我很久没用VB了,有点忘了,感激不尽

Private Sub Command1_Click()
Dim linestr
Dim allstr
Open "d:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, linestr
allstr = allstr & Trim(linestr) & " "
Loop
Close #1
allstr = Trim(allstr)
allstr = Replace(allstr, " ", vbCrLf)
Open "d:\1.txt" For Output As #2
Print #2, allstr
Close #2
End Sub

'复制下面代码,运行即可。

Private Sub Form_Load()
Dim i As Integer, S As String, b() As String
Dim FileName As String
FileName = InputBox("请输入要转换的文件名:")
If FileName = "" Or Dir(FileName) = "" Then
MsgBox "文件名不正确!"
Exit Sub
End If
Open FileName For Input As #1 '打开要转换的文件
Open "c:\~2.txt" For Output As #2 '打开临时文件
Do While Not EOF(1)
Line Input #1, S '取出一行
S = Trim(S)
Do While InStr(S, " ") > 0 '把多空格转换成