首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

请教怎样把一个矩阵格式的文本文件读入二维数组

2012-01-07 
请问怎样把一个矩阵格式的文本文件读入二维数组?请问怎样把一个矩阵格式的文本文件读入二维数组?文本文件

请问怎样把一个矩阵格式的文本文件读入二维数组?
请问怎样把一个矩阵格式的文本文件读入二维数组?

文本文件数据格式如下:

+2.533510E+000 +2.533500E+000 +2.533500E+000 +2.533500E+000
-2.533500E+000 +2.533500E+000 +2.533500E+000 +2.533500E+000
+2.533500E+000 +2.533500E+000 +2.533500E+000 +2.533500E+000
+2.533500E+000 +2.533500E+000 +2.533500E+000 +2.533516E+000

要求读入 data(4,4) 中去。 
ps: 我用input, 弄来弄去都跑不通:

......

Open "data.txt" For Input As #1
Dim matrix() As Double
For i = 1 To 4
  Input #1, matrix(i)
Next
Close #1

......

[解决办法]
Private Sub Command1_Click() 
Dim s() As String, data(3, 3) As Double, i As Long, j As Long, temp() As String
Open "d:\data.txt" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
For i = 0 To 3
temp = Split(s(i))
For j = 0 To 3
data(i, j) = CDbl(temp(j))
Next
Next

For i = 0 To 3
For j = 0 To 3
Debug.Print data(i, j);
Next
Debug.Print
Next

End Sub

热点排行