'从字段中读取数据,并保存为文件 Function FieldToFile(FileName As String, fdObject As ADODB.Field) As BooleanDim lChunkCount As Long Dim lChunkRemainder As Long Dim i As Long Dim j As LongOn Error GoTo errHandFieldToFile = False If fdObject.ActualSize = 0 Then Exit Function ReDim Chunk(CHUNK_SIZE) lChunkCount = fdObject.ActualSize \ CHUNK_SIZE '获得文件的块数 lChunkRemainder = fdObject.ActualSize Mod CHUNK_SIZE '整块后余下的数据 j = FreeFile(0) If Len(Dir(FileName)) Then Kill FileName Open FileName For Binary As j ReDim Chunk(fdObject.ActualSize)StatusBar1.Panels(1).Text = "正在下载文件" If lChunkRemainder > 0 Then ProgressBar1.Max = lChunkCount + 1 Else ProgressBar1.Max = lChunkCount End If ProgressBar1.Value = 0 ProgressBar1.Visible = TrueFor i = 1 To lChunkCount ReDim Buffer(CHUNK_SIZE) Chunk() = fdObject.GetChunk(CHUNK_SIZE) '取一块 Put j, , Chunk() '将块写入临时文件 ProgressBar1.Value = i NextIf lChunkRemainder > 0 Then ReDim Chunk(lChunkRemainder) Chunk() = fdObject.GetChunk(lChunkRemainder) '取余下的数据 Put j, , Chunk() '将其写入临时文件 ProgressBar1.Value = lChunkCount + 1 End IfClose j If (FileLen(FileName)) > 0 Then FieldToFile = True StatusBar1.Panels(1).Text = "" ProgressBar1.Visible = False Exit Function errHand: StatusBar1.Panels(1).Text = "" ProgressBar1.Visible = False MsgBox Err.Description Close j FieldToFile = False End Function
Function FieldToFile(FileName As String, fdObject As ADODB.Field) As BooleanDim lChunkCount As Long
Dim lChunkRemainder As Long
Dim i As Long
Dim j As LongOn Error GoTo errHandFieldToFile = False
If fdObject.ActualSize = 0 Then Exit Function
ReDim Chunk(CHUNK_SIZE)
lChunkCount = fdObject.ActualSize \ CHUNK_SIZE '获得文件的块数
lChunkRemainder = fdObject.ActualSize Mod CHUNK_SIZE '整块后余下的数据
j = FreeFile(0)
If Len(Dir(FileName)) Then Kill FileName
Open FileName For Binary As j
ReDim Chunk(fdObject.ActualSize)StatusBar1.Panels(1).Text = "正在下载文件"
If lChunkRemainder > 0 Then
ProgressBar1.Max = lChunkCount + 1
Else
ProgressBar1.Max = lChunkCount
End If
ProgressBar1.Value = 0
ProgressBar1.Visible = TrueFor i = 1 To lChunkCount
ReDim Buffer(CHUNK_SIZE)
Chunk() = fdObject.GetChunk(CHUNK_SIZE) '取一块
Put j, , Chunk() '将块写入临时文件
ProgressBar1.Value = i
NextIf lChunkRemainder > 0 Then
ReDim Chunk(lChunkRemainder)
Chunk() = fdObject.GetChunk(lChunkRemainder)
'取余下的数据
Put j, , Chunk() '将其写入临时文件
ProgressBar1.Value = lChunkCount + 1
End IfClose j
If (FileLen(FileName)) > 0 Then FieldToFile = True
StatusBar1.Panels(1).Text = ""
ProgressBar1.Visible = False
Exit Function
errHand:
StatusBar1.Panels(1).Text = ""
ProgressBar1.Visible = False
MsgBox Err.Description
Close j
FieldToFile = False
End Function