我要在VB程序里读记事本里的矩阵(记事本里的内容只有一个矩阵),我想设一个数组和这个矩阵对应起来,比如说矩阵为 
1 2 3 
3 4 5 
6 7 8 
数组为a(2,2),这个记事本文件应该怎样读入VB程序,将矩阵的值赋给这个数组呢?也就是说在VB里读入这个记事本,1就自动赋给a(0,0),2自动赋给a(0,1).......。 
知道的朋友麻烦你说一下,我急着用啊。 

解决方案 »

  1.   

    Sub getmatrix(ByVal filepath As String, ByRef matrix() As String)
    Dim s As String, temp() As String, temp1() As String, rows As Long, cols As Long, i As Long, j As Long
    Open filepath For Binary As #1
    s = Space(LOF(1))
    Get #1, , s
    Close #1
    temp = Split(s, vbCrLf)
    rows = UBound(temp)
    cols = UBound(Split(temp(0), " "))
    ReDim matrix(rows, cols)
    For i = 0 To rows
    temp1 = Split(temp(i), " ")
    For j = 0 To cols
    matrix(i, j) = temp1(j)
    Next
    Next
    Erase temp1
    Erase tempEnd SubPrivate Sub Command1_Click()
    Dim x() As String, i As Integer, j As Integer
    getmatrix "c:\xxx.txt", x
    For i = 0 To UBound(x, 1)
    For j = 0 To UBound(x, 2)
    Print x(i, j); " ";
    Next
    Print
    Next
    End Sub
      

  2.   

    可能是问题太简单的原因啊,等了这么久,只有狼行天下给予热情地回复.咳,不管怎样,非常感谢northwolves. 结题了.