请问怎样把一个矩阵格式的文本文件读入二维数组?
请问怎样把一个矩阵格式的文本文件读入二维数组?
文本文件数据格式如下:
+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