日期:2014-01-30  浏览次数:20439 次


Dim Buffer As String
Dim BufferSize As Integer
Dim fileLength As Long, SuperBuffer As Long
Dim PercentDone As Long, b As Integer

Open xFileName For Binary Access Read As #i         'open the file to read
        fileLength = LOF(i)

        If LOF(i) <> 0 Then
            Do While Not EOF(i): DoEvents
                If fileLength - Loc(i) < BufferSize Then
                    Let BufferSize = fileLength - Loc(i)
                    If BufferSize = 0 Then GoTo done
                End If
               
                Buffer = Space(BufferSize)
                Get #i, , Buffer
               
                SuperBuffer = SuperBuffer + Len(Buffer)
                Debug.Print "BufferSize=" & BufferSize & " SuperBuffer=" & SuperBuffer & " loc(" & i & ")=" & Loc(i)
            Loop
        End If
Close #i


//立即窗口打印结果:
BufferSize=2048 SuperBuffer=2048 loc(1)=2188
BufferSize=2048 SuperBuffer=4096 loc(1)=5146
.......
.......
BufferSize=2048 SuperBuffer=22571008 loc(1)=32422628
BufferSize=56 SuperBuffer=22571064 loc(1)=32422690

//问题:
文件大小实际是30.9M,但最后只能传输到28.1M就结束了,问题出在文件读取的位置loc(1)和实际传输的文件大小不同步,在
If fileLength - Loc(i) < BufferSize Then
   Let BufferSize = fileLength - Loc(i)
   If BufferSize = 0 Then GoTo 结束过程
End If
这个过程判断时及早结束读取。

请各位大侠指点,如能解决本人不胜感激,必有高分酬谢!
可将解决方法发送本人邮箱:caopengzhao@sohu.com ,也可直接写到这里,谢谢各位!