有一组数据例如
1781  2562  3493 4445 5523 6616 .....
2452  4565  3435 8676 4561 2556 .....
....
...
数据排列很整齐
我想按照行列好来取其中的某个数据
如果用VB的数组来处理的话,一个一个的赋值很麻烦
能否采用读去数据文件的方法来赋值呢?
怎样处理起来比较简单
请 高手赐教
非常感谢

解决方案 »

  1.   

    数据源是什么形式存在的?
    如果是数据库,直接:
    dim rs as adodb.recordset
    dim arr()
    ...
    rs.open "select * from ..."
    arr=rs.getrow()
    ...如果是文本之类,可以先读到string里再用split来赋给数组就可以了
      

  2.   

    不是数据库文件如果是文本之类,可以先读到string里再用split来赋给数组就可以了怎么实现呢?
      

  3.   

    比如在a.txt记录着这些:
    1781  2562  3493 4445 5523 6616 .....
    2452  4565  3435 8676 4561 2556 .....
    ....
    ...
    并且两项之间如果是vbtab(表格符)分开的话。
    dim strLine as string
    dim strTxt as string
    dim arr()
    open "c:\a.txt" for input as #1
    do while not eof(1)
     line input #1,strline
     strtxt=strtxt & vbcrlf & strline
    loop
    close #1
    strtxt=trim(strtxt)
    arr=split(strtxt,vbtab)
    ...
      

  4.   

    Dim Cols, i As Integer
    Dim TextLine As String
    Dim ArrayLine() As String
    Dim myData() As IntegerOpen "yourdata.txt" For Input As #1
    Do While Not EOF(1)   ' 循环至文件尾。
       Line Input #1, TextLine   ' 读入一行数据并将其赋予某变量。
       ArrayLine = Split(TextLine, "  ") '如果分隔符是制表符,参数 2 为 vbTab
       Cols = Ubound(ArrayLine) + 1
       Redim Preserve myData(Ubound(myData) + Cols) 
       For i = Cols - 1 to 0 Step -1
          myData(Ubound(myData) - i) = Val(ArrayLine(Cols - 1 - i))
       Next i
    Loop
    Close #1   ' 关闭文件。'通过行、列读数据
    Dim row, col As Integer
    row = Val(txtRow)
    col = Val(txtCol)
    MsgBox mtdata(row * Cols + col)