求教,怎样让该段代码可以传输BMP图片
这是我看到的一个程序里的部分代码,用来传送文本文件没问题,可是传送别的就不行了,谁能给改改,谢谢
Public Sub SendFile(FileName As String, WinS As Winsock)
Dim FreeF As Integer
Dim LenFile As Long
Dim nCnt As Long
Dim LocData As String
Dim LoopTimes As Long
Dim i As Long
FreeF = FreeFile
Open FileName For Binary As #99
nCnt = 1
LenFile = LOF(99)
WinS.SendData "|FILESIZE| " & LenFile
DoEvents
Sleep (400)
Do Until nCnt > = (LenFile)
LocData = Space$(1024) 'Set size of chunks
Get #99, nCnt, LocData 'Get data from the file nCnt is from where to start the get
If nCnt + 1024 > LenFile Then
WinS.SendData Mid$(LocData, 1, (LenFile - nCnt))
Else
WinS.SendData LocData 'Send the chunk
End If
nCnt = nCnt + 1024
Loop
Close #99
End Sub
[解决办法]
你是用WinSock传文件吧?
你试试这样做
dim gbytSum() as byte
private sub command1_click()
open app.path & "\aaa.jpg " for binary as #1
get #1,,gbytSum
close #1
winsock1.senddata "aaa.jpg "
doevents
winsock1.senddata gbytSum
end sub
收的时候先获取对方发过来的文件名 "aaa.jpg "然后
open app.path & "\aaa.jpg " for binary as #1
打开文件,但暂不关闭,再获取文件内容,将文件内容同样读入一二进制数组中
再将二进制数组写入文件
put #1,,bytSum
全部写完后再关闭文件
close #1
如果还有不明白的话,我可以做个例子发给你看