我通过open filename for binary as #1命令将包含有数字,中文字符的信息写入了一个.dat后缀的二进制文件
现在该如何正确的读取里面的信息并把他还原成正确的数字,中文字符?

解决方案 »

  1.   

    你是怎么写的就怎么读取:Dim FileName As String, strTmp As String
    FileName = "c:\test.dat"
    strTmp = "包含有数字123等,中文字符的信息"
    '写入dat文件
    Open FileName For Binary As #1
    Put #1, 1, strTmp
    Close #1'读取
    Open FileName For Binary As #1
    strTmp = Space(LOF(1))
    Get #1, 1, strTmp
    Close #1
    Debug.Print strTmp
      

  2.   

    你的数据应该有个结构定义吧。把这个结构作为一个基本单元来写入或者读出。MSDN里有现成的例子。
      

  3.   

    是有个结构
    结构如下:从sqlserver数据库中读出记录后按固定结构写入二进制文件
      

  4.   

    Mid      As Integer
           fid      As Integer
           rrid     As String
           sjr      As String
           title   As String
           phone      As String
           sj     As Date
           ftype      As String
           hj         As String
           mj         As String
           sendflag    As Integer
      

  5.   

    参考:Private Type pRecord  ' 定义用户自定义数据类型。
        strName As String * 20
        dtdate As Date
        strSex As String * 2
        intAge As Integer
    End TypePrivate Sub Command1_Click()
        Dim FileName As String, myRecord As pRecord
        FileName = "c:\test.dat"
        
        Dim i As Long
        For i = 1 To 5
            myRecord.strName = "姓名" & i
            myRecord.dtdate = "2006-04-20"
            myRecord.strSex = "男"
            myRecord.intAge = i + 20
            
            '写入dat文件
            Open FileName For Binary As #1
            Put #1, i * Len(myRecord), myRecord
            Close #1
        Next
        
        Dim tmpRecord As pRecord
        For i = 1 To 5
            '读取
            Open FileName For Binary As #1
            Get #1, i * Len(tmpRecord), tmpRecord
            Close #1
            Debug.Print tmpRecord.dtdate
            Debug.Print tmpRecord.intAge
            Debug.Print tmpRecord.strName
            Debug.Print tmpRecord.strSex
            Debug.Print String(100, "=")
        Next    
    End Sub
      

  6.   

    您的这个例子可以,但我的还是不行
    能否在短消息里留个qq,我将我的dat文件传给您
    谢谢各位的回答