利用VB读取TXT文件中的数据并输出 150
有很多txt文件,每个TXT文件中都存放了5行5列的数据。我想利用VB将每个TXT中的(1,1)位置处的数据读取出来,按顺序存放在一个新的TXT文件中;将每个TXT中的(...
有很多txt文件,每个TXT文件中都存放了5行5列的数据。我想利用VB将每个TXT中的(1,1)位置处的数据读取出来,按顺序存放在一个新的TXT文件中;将每个TXT中的(1,2)位置处的数据读取出来,按顺序存放在一个新的TXT文件中......以此类推,最后得到25个新的TXT文件
展开
4个回答
展开全部
给你一个参考谈渣程序。测试正常。朋友
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
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
展开全部
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
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
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个我可以给你做。
读写文件的事情而已
读写文件的事情而已
追问
能否发个代码上来?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(1,1)、(1,2)表示什么,不清楚。
追问
第一行第一列 第一行第二列的意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询