"
         D
  1  69.2723   0.569
         D
  2  69.2735   0.569
         D
  3  69.2735   0.569
         D
  4  69.2734   0.568
         D
 D1 304.4237   0.490
         D
  5  81.1011   0.490
         D
  6  99.1348    1.00
        D1
  7   0.0008   0.977
        D1
  8   0.0006   0.976"
怎样将以上的数据读取 然后放到vb 的grid控件中显示出来。可以不要空格但是显示的格式要和上面的一样。

解决方案 »

  1.   

    dim ls_Content() As String
    dim s as string
    dim i as long Open App.Path & "d:\aa.txt" For Input As #1
    s = StrConv(InputB(LOF(1), #1), vbUnicode) 
    Close #1ls_Content = Split(s, vbCrLf)
    for i=0 to UBound(ls_Content, 1)
        debug.print ls_Content(i)'这里就将你的文件一行行分开了
    next i
      

  2.   

    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Const ForReading = 1
    Set readFile = objFSO.OpenTextFile ("c:\11.txt", ForReading)
    Do while not readFile.AtEndOfStream
       StrLine = readFile.Readline
       '读出行后在这里对字符串做处理,解析出有用的数据
    Loop
    readFile.Close
    Set readFile = Nothing
    Set objFSO = Nothing
      

  3.   

    tztz520(午夜逛街):
    这一步我做出来了,我的意思是 能不能将每行再按列分割阿?
      

  4.   

    >这一步我做出来了,我的意思是 能不能将每行再按列分割阿?可以。你的列分隔符是什么?
    如果仅仅是 Tab:
    Dim strFields() As String
    ......
    strFields = Split(strRow(i), vbTab)
    For j = 0 To Ubound(strFields)
        msFlexGrid1.TextMatrix(i, j) = strFields(j)
    Next j
    ......如果是多个空格,首先合并空格:
    ......
    Do While Instr(strRow(i), Space(2))
        strRow(i) = Replace(strRow(i), Space(2), Space(1))
    Loop
    strFields = Split(strRow(i), Space(1))
    For j = 0 To Ubound(strFields)
        msFlexGrid1.TextMatrix(i, j) = strFields(j)
    Next j
    ......
      

  5.   

    ls_Content = Split(你的行的字符串, " ")'这用空格分开了字符,你处理ls_Content(x)的时候如果为空就不处理,如果有字符就处理.
      

  6.   

    如果文件比较大,还是建议使用数据库方式读取,参考
    http://community.csdn.net/Expert/topic/3095/3095485.xml?temp=.9600489