比如一个文件有900字节,我需要分三次读取,第1次200字节,第二次400字节,第三次300字节,怎么做的??

解决方案 »

  1.   

    dim fdata() as byte
    open "e:\1.dat" for binary as #1redim fdate(200-1)
    get #1,1,fdataredim fdate(400-1)
    get #1,,fdataredim fdate(300-1)
    get #1,,fdataclose #1
      

  2.   

    Dim aChunkSizes() as Byte
    Dim readRtn as long
    'hFile 是你的文件handle,用CreateFile API得到
    SetFilePointer hFile, 0&, 0&, 0&  
    ReDim aChunkSizes(0 To 199)
    ReadFile hFile, aChunkSizes(0), 200, readRtn, ByVal 0& 
    If readRtn=200 then
    Debug.Print "Read First part successfully"
    '你的后续处理程序在这里处理
    Else
    CloseHandle hFile
    Exit Sub
    End IfReDim aChunkSizes(0 To 399)
    ReadFile hFile, aChunkSizes(0), 400, readRtn, ByVal 0& 
    If readRtn=400 then
    Debug.Print "Read 2nd part successfully"
    '你的后续处理程序在这里处理
    Else
    CloseHandle hFile
    Exit Sub
    End IfReDim aChunkSizes(0 To 299)
    ReadFile hFile, aChunkSizes(0), 300, readRtn, ByVal 0& 
    If readRtn=300 then
    Debug.Print "Read Last part successfully"
    '你的后续处理程序在这里处理
    Else
    CloseHandle hFile
    Exit Sub
    End IfIf Not hFile = 0&  then CloseHandle hFile
      

  3.   

    中间可以再用SetFilePointer重新定位,但ReadFile会自动顺序读起。
      

  4.   

    对于二进制打开方式,用seek方法就可以定位,这是VB提供的
      

  5.   

    用API比较好,支持Unicode.我从不用VB自带的Open...Put...Get...Seek..Close...