我自己做了一个,文本文件没有问题,可是我传BMP的时候就发生两个文件不一致的情况,看来是我的方法问题,大家有没有好一点的方法,各给我参考参考。谢了!
解决方案 »
- VB如何实现字符串(包括大小写字母、数字)与二进制的相互转换?
- 怎么在98下面屏蔽并且处理Alt+TAB,Alt+space,```````等等
- frame中内容的打印问题
- 求教小程序!(刚学,请大家不要见笑)
- 请问文本框的多行显示不折行应该怎么做(高分赠送)
- 如何更换一个exe文件的图标?
- 请问VB中的换行符是什么?
- 如何向另一个程序中的按钮发送单击消息!
- 请问:在IE下,点击按钮后,打开word文件,有何方法实现??
- 已知一个SUB的地址,怎样调用?(在同一工程内)
- API的bitblt函数怎么用?具体有作什么的?是把图片加载到内存吗?然后怎么处理?
- ActiveReport问题:有15字段列,自动生成每页打3个字段列格式的报表
Dim LenFile As Long
Dim nCnt As Long
Dim LocData() As Byte
Dim Tempstr As String
Dim a() As Byte
Dim i As Long
Dim myHead As StringFreeF = FreeFile
Open FileName For Binary As FreeF nCnt = 1
LenFile = FileLen(FileName)
Tempstr = IIf(Right$(RemoteFilePath, 1) = "\", RemoteFilePath & _
Right$(FileName, Len(FileName) - InStrRev(FileName, "\")), RemoteFilePath & _
"\" & Right$(FileName, Len(FileName) - InStrRev(FileName, "\")))
myHead = "|FILESEND|" & Tempstr & "|" & CStr(LenFile)
WinS.SendData myHead
objProBar.Value = 0
objProBar.Max = Fix(LenFile / SendDataSize) + 1
objProBar.Visible = True
Sleep (300)
Do Until nCnt > (LenFile)
DoEvents
If nCnt + SendDataSize - 1 > LenFile Then
ReDim LocData(LenFile - nCnt) As Byte
Else
ReDim LocData(SendDataSize - 1) As Byte
End If
Get FreeF, nCnt, LocData 'Get data from the file nCnt is from where to start the get
WinS.SendData LocData
nCnt = nCnt + SendDataSize
objProBar.Value = objProBar.Value + 1
Loop
Close FreeF
objProBar.Value = objProBar.Max
objProBar.Visible = False
End Sub
'RemoteFilePath 是个远端接收文件的地址(包含全路经,不包括文件名)
'WinS是个Winsock对象,objProBar是个进度条对象
'const SendDataSize =1024
Dim FreeF As Integer
Dim LenFile As Long
Dim nCnt As Long
Dim LocData() As Byte
Dim Tempstr As String
Dim a() As Byte
Dim i As Long
Dim myHead As StringFreeF = FreeFile
Open FileName For Binary As FreeF nCnt = 1
LenFile = FileLen(FileName)
Tempstr = IIf(Right$(RemoteFilePath, 1) = "\", RemoteFilePath & _
Right$(FileName, Len(FileName) - InStrRev(FileName, "\")), RemoteFilePath & _
"\" & Right$(FileName, Len(FileName) - InStrRev(FileName, "\")))
myHead = "|FILESEND|" & Tempstr & "|" & CStr(LenFile)
WinS.SendData myHead '发送头和文件名及文件总长度!
objProBar.Value = 0
objProBar.Max = Fix(LenFile / SendDataSize) + 1
objProBar.Visible = True
Sleep (300) '一个api函数
Do Until nCnt > (LenFile)
DoEvents
If nCnt + SendDataSize - 1 > LenFile Then
ReDim LocData(LenFile - nCnt) As Byte
Else
ReDim LocData(SendDataSize - 1) As Byte
End If
Get FreeF, nCnt, LocData 'Get data from the file nCnt is from where to start the get
WinS.SendData LocData
nCnt = nCnt + SendDataSize
objProBar.Value = objProBar.Value + 1
Loop
Close FreeF
objProBar.Value = objProBar.Max
objProBar.Visible = False
End Sub'我自己的接收端程序:Private Sub objTCP_DataArrival(Index As Integer, ByVal bytesTotal As Long) Dim strData As String
Dim sData As String
Dim lRet As Long
Dim DataByte() As Byte
objTCP(intmax).GetData DataByte
strData = StrConv(DataByte, vbUnicode)
If Is_FILESEND = True Then 'Is_FILESEND是个全局变量
Put #myFreeFile, , DataByte
SendFileLen = SendFileLen - UBound(DataByte) - 1
If SendFileLen <= 0 Then
Close #myFreeFile
myFreeFile = 0
Is_FILESEND = False
End If
Else
If InStr(1, strData, "|FILESEND|") <> 0 Then
Dim sFileName As String
Dim k As Integer
Is_FILESEND = True
k = InStr(11, strData, "|")
sFileName = Mid$(strData, 11, k - 11)
SendFileLen = CLng(right$(strData, Len(strData) - k))
myFreeFile = FreeFile
Open sFileName For Binary As myFreeFile
End If ......... '其他程序End If