文档格式如下:
11:41:15     0    32    32    32    31    31    31     64    50    26    26    26    
11:41:16     1    32    32    32    25    31    31    65    50    26    26    26   每个值都要读入不同的变量,请问如何用程序实现?

解决方案 »

  1.   

    'ReadFileLine用于读取任意一行,行号从1开始
    'GetAllElement用于取得各列的值。
    public type Mydata
      Element1 as string
      ...............
      Element13 as string
    end typepublic function GetAllElement(byval strLine as string,optional SplitChar=space(1)) as mydatadim AllElementAllElement=split(strline,splitchar)
    with GetAllElement
      .Element1=AllElement(0)
     ........
    end with
    end functionpublic function ReadFileLine(ByVal strFile As String,byval lngLineNo as long) as string
    dim strContent as string
    dim ALLLine
    strcontent=ReadFileAsString(strfile)
    allline=split(strcontent,vbcrlf)
    ReadFileLine=allline(lnglineno-1)
    end function
    Public Function ReadFileAsByte(ByVal strFile As String, ByRef FileByte() As Byte) As Long
      Dim hFile As Long
      Dim lngFileSize As Long
      Dim bRead As Long
      Dim TmpPos As Long
      Dim Sum As Long
      Dim dwBytesRead As Long
      Dim pBuffer(64511) As Byte
       
      'If FileExist(strFile) = False Then Exit Function
      hFile = CreateFile(strFile, GENERIC_READ, FILE_SHARE_READ, 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)
      If hFile = INVALID_HANDLE_VALUE Then Exit Function
      lngFileSize = GetFileSize(hFile, 0&)
      If lngFileSize <= 0 Then Exit Function
      ReDim FileByte(lngFileSize) As Byte
      Sum = 0
        Do
               DoEvents: DoEvents: DoEvents
               bRead = ReadFile(hFile, pBuffer(0), 64511, dwBytesRead, 0&)
               TmpPos = VarPtr(FileByte(0)) + Sum
               CopyMemory ByVal TmpPos, ByVal VarPtr(pBuffer(0)), ByVal dwBytesRead
               Sum = Sum + dwBytesRead
               DoEvents: DoEvents: DoEvents
      Loop Until Sum >= lngFileSize
      
      ReadFileAsByte = lngFileSize
      CloseHandle hFile
    End Function
    Public Function ReadFileAsString(ByVal strFile As String) As String
    Dim FileByte() As Byte
    ReadFileAsByte strFile, FileByte()
    ReadFileAsString = StrConv(FileByte(), vbUnicode) 'Byte2StringEnd Function
      

  2.   

    Private Sub Command1_Click()
    Dim x() As String, y() As String, b() As Byte, temp() As String, i As Integer, j As Integer
    Open "c:\xx.txt" For Binary As #1
    ReDim b(LOF(1))
    Get #1, , b
    Close #1
    x = Split(StrConv(b, vbUnicode), vbCrLf)
    Erase b
    ReDim y(UBound(x), 13)
    For i = 0 To UBound(x)
    temp = Split(x(i), "    ")
    If UBound(temp) = 1 Then
    Exit For
    Else
    For j = 0 To UBound(temp)
    y(i, j) = temp(j)
    Next
    MsgBox Join(temp, vbCrLf), 0, y(i, 0)
    End If
    Next
    End Sub