文件分块函数:Public Sub FiletoSeg(filename As String, Optional ChunkSize As Long = 8192) '8192为每段长度 Dim fnum As Integer, bytesleft As Long, bytes As Long,Seg As Byte Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then Err.Raise 1001, , "field doesn't support the GetChunk method." End If
If Dir$(filename) = "" Then Err.Raise 53, , "文件未找到"
fnum = FreeFile Open filename For Binary As fnum bytesleft = LOF(fnum)
Do While bytesleft bytes = bytesleft
If bytes > ChunkSize Then bytes = ChunkSize ReDim tmp(1 To bytes) As Byte Get fnum, , tmp
Dim fnum As Integer, bytesleft As Long, bytes As Long,Seg As Byte
Dim tmp() As Byte
If (fld.Attributes And adFldLong) = 0 Then
Err.Raise 1001, , "field doesn't support the GetChunk method."
End If
If Dir$(filename) = "" Then Err.Raise 53, , "文件未找到"
fnum = FreeFile
Open filename For Binary As fnum
bytesleft = LOF(fnum)
Do While bytesleft
bytes = bytesleft
If bytes > ChunkSize Then bytes = ChunkSize
ReDim tmp(1 To bytes) As Byte
Get fnum, , tmp
Seg = tmp 'Seg是其中一块,你从这里发送(串口)
bytesleft = bytesleft - bytes
Loop
Close #fnum
End Sub本函数运行结束,你的文件也传结束了。