利用VB读取TXT文件中的数据并输出

有很多txt文件,每个TXT文件中都存放了5行5列的数据。我想利用VB将每个TXT中的(1,1)位置处的数据读取出来,按顺序存放在一个新的TXT文件中;将每个TXT中的(1,2)位置处的数据读取出来,按顺序存放在一个新的TXT文件中......以此类推,最后得到25个新的TXT文件

给你一个参考程序。测试正常。朋友
Option Base 1
'运行程序前,先在D盘上创建test和test_new两个文件夹
Private Sub Command1_Click() '创建五个.txt文件存放于test中
Dim a%(5, 5), k%, f%
For f = 1 To 5
Open "d:/test/" & f & ".txt" For Output As #f

For i = 1 To 5
For j = 1 To 5
k = k + 1
a(i, j) = k: Print #f, a(i, j) & " ";
Next j
Print #f, vbCr
Next i
Next f
Close
End Sub
Private Sub Command2_Click() '产生25个新.txt文件存放于test_new中
Dim a%(5, 6), b$, k%, m%, f%, q%, r%
Me.Cls
For k = 1 To 5
For m = 1 To 5
For f = 1 To 5
Open "d:/test/" & f & ".txt" For Input As #f
For q = 1 To 5
If Not EOF(f) Then
Input #f, a(q, 1), a(q, 2), a(q, 3), a(q, 4), a(q, 5), a(q, 6)
End If
Next q
Close
b = b & " " & a(k, m)
Next f
Print b '结果同时输出到窗体
r = r + 1
Open "d:/test_new/" & r & ".txt" For Output As r
Print #r, b
Close
b = ""
Next m
Next k
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2016-06-09
Private Sub Command1_Click()
Dim ss() As String, s As String
Dim tt() As String, t As String
Dim sum As Long
Dim myfile As String
Dim i As Integer, j As Integer

myfile = "d:\1.txt" ‘要读取的文件
Open myfile For Input As #1
s = StrConv(InputB(LOF(1), #1), vbUnicode)
Close #1
ss = Split(s, vbCrLf)

Open myfile For Output As #1
For i = 0 To UBound(ss)
tt = Split(ss(i), " ")
t = ""
For j = 0 To UBound(tt)
If tt(j) <> "" Then
t = t & tt(j) & "+"
sum = sum + Val(tt(j))
End If
Next j
t = Left(t, Len(t) - 1) & "=" & sum
Print #1, t
Next i
Close
End Sub本回答被网友采纳
第2个回答  2016-06-07
这个我可以给你做。
读写文件的事情而已追问

能否发个代码上来?

第3个回答  2016-06-07
(1,1)、(1,2)表示什么,不清楚。追问

第一行第一列 第一行第二列的意思

相似回答