vb中如何将文本文件中的矩阵式数据读入二维数组
要实现的功能为:一个文本文件中有已知列数而行数未知的矩阵格式的数据,数据之间用空格分开,文本中除了数据外还有其他字符(这些字符在数据后面,为一些参数说明),我如何将这些数...
要实现的功能为:一个文本文件中有已知列数而行数未知的矩阵格式的数据,数据之间用空格分开,文本中除了数据外还有其他字符(这些字符在数据后面,为一些参数说明),我如何将这些数据读入一个二维数组一般进行处理呢
展开
展开全部
11 12 13 14 15 这个都放文件里 这行算注释
21 22 23 24 25
31 32 33 34 35
Private Sub Form_Load()
Dim b() As String
Open "c:\1.txt" For Input As 1
i = 0
Do While Not EOF(1)
Line Input #1, d
i = i + 1
Loop
Close 1
ReDim a(i - 1, 4) As String
Open "c:\1.txt" For Input As 1
i = 0
Do While Not EOF(1)
Line Input #1, tmp
b() = Split(tmp, " ")
For j = 0 To 4
a(i, j) = b(j)
Next
i = i + 1
Loop
Close 1
End Sub
21 22 23 24 25
31 32 33 34 35
Private Sub Form_Load()
Dim b() As String
Open "c:\1.txt" For Input As 1
i = 0
Do While Not EOF(1)
Line Input #1, d
i = i + 1
Loop
Close 1
ReDim a(i - 1, 4) As String
Open "c:\1.txt" For Input As 1
i = 0
Do While Not EOF(1)
Line Input #1, tmp
b() = Split(tmp, " ")
For j = 0 To 4
a(i, j) = b(j)
Next
i = i + 1
Loop
Close 1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先把这些数据读到一个1维的数组里面吧,然后再对这个1维数组时行处理,把里面的值按照规律赋给一个2维数组
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
文本文件C:\1.txt:
10 20 3 1 注释1
3213 42371 121 32 注释2
程序(以下Matrix是数值,如果你要字符串请更改为Dim Matrix() As String):
Dim Matrix() As Long
Private Sub Form_Load()
Const Column As Integer = 4 '设置列数
Dim l As String, p() As String
Dim i As Integer, lc As Integer
Open "C:\1.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve Matrix(Column - 1, lc)
Line Input #1, l: p = Split(l, " ")
For i = 0 To Column - 1: Matrix(i, lc) = p(i): Next
lc = lc + 1
Loop
Close #1
End Sub
10 20 3 1 注释1
3213 42371 121 32 注释2
程序(以下Matrix是数值,如果你要字符串请更改为Dim Matrix() As String):
Dim Matrix() As Long
Private Sub Form_Load()
Const Column As Integer = 4 '设置列数
Dim l As String, p() As String
Dim i As Integer, lc As Integer
Open "C:\1.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve Matrix(Column - 1, lc)
Line Input #1, l: p = Split(l, " ")
For i = 0 To Column - 1: Matrix(i, lc) = p(i): Next
lc = lc + 1
Loop
Close #1
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
容易,我可以帮你。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询