| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2007 人关注过本帖
标题:[求助]我的文件传送程序
取消只看楼主 加入收藏
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
结帖率:100%
收藏
 问题点数:0 回复次数:5 
[求助]我的文件传送程序

请大家帮我看看哪里错了:我用了udp连接,另外复制了此程序做为通信的另一方,请大家务必帮我解决
请问如果放在不同机上能否传txt文件?
Dim a As String

Private Sub Command1_Click()
Dim bytdate() As Byte
Dim filename As String
Dim lngfile As Long
Dim i As Long
filename = Dir1.Path + "\" + File1.filename
lngfile = FileLen(filename) \ 1024
For i = 0 To lngfile
ReDim myfile(1023) As Byte
Open filename For Binary As #1
Get #1, i * 1024 + 1, myfile
Close #1
ws1.SendData myfile
DoEvents
Next i
End Sub


Private Sub Command2_Click()
With ws1
.RemoteHost = Text1.Text
.RemotePort = 5001
.Bind 5001
End With
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
a = File1.filename
End Sub

Private Sub ws1_DataArrival(ByVal bytesTotal As Long)
Static i As Long
Dim myfile() As Byte
Dim mylong As Double
Dim mypath As String
Dim fn As Integer
fn = FreeFile
mypath = "d:\a\a.txt
ReDim myfile(bytesTotal - 1)
ws1.GetData myfile
fn = FreeFile
Open mypath For Binary As #fn
Put #fn, mylong + 1, myfile
Close #fn
End Sub

[此贴子已经被作者于2007-11-21 1:53:17编辑过]

搜索更多相关主题的帖子: 文件 
2007-11-21 01:07
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
收藏
得分:0 
谢谢大家拉,ls的程序我看了,学了很多,不懂在请教你们
2007-11-25 18:11
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
收藏
得分:0 
请问redice,这段程序是什么意思(在你那个聊天系统的)
For i = 1 To LOF(filenum) \ 7168   '循环发送文件的数据,每次发送5K
        '是否要在此处加一个缓冲时间
        complete = False  '发送该数据包前将发送完成的标记设为 fasle
        Get filenum, m, size '读取指定大小的数据
        m = 7168 * i
        Winsock1.SendData size '发送数据
        DoEvents
        While Not complete '检测发送上面的数据是否发送完成,如果完成则继续原来循环
        DoEvents
        Wend
    Next
    If Int(LOF(filenum)) > Int((LOF(filenum) \ 7168) * 7168) Then '将未发送完的数据发送了
       ReDim size(LOF(filenum) - (LOF(filenum) \ 7168) * 7168)
       Get filenum, m, size
       Winsock1.SendData size
    End If
2007-11-29 23:57
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
收藏
得分:0 
谢拉
2007-12-01 23:50
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
收藏
得分:0 
请问redice,我模拟了你的一些程序,但为什么只传到了8k,帮我看看
Dim complete As Boolean
Dim fn As String
Dim fn1 As String
Dim fn2 As String
Dim num As Long
Private Sub Command1_Click()
With ws
 .RemoteHost = Text1.Text
 .RemotePort = 5000
End With
With ws2
.RemoteHost = Text1.Text
.RemotePort = 5001
End With
End Sub

Private Sub Command3_Click()
cd1.ShowOpen
Text2.Text = cd1.FileTitle
fn = "D:\唐\ad\" + cd1.FileTitle
ws2.SendData fn
End Sub

Private Sub Form_Load()
ws.LocalPort = 5000
ws.Bind
ws2.LocalPort = 5001
ws2.Bind
ws3.Bind 5002
num = 1
End Sub

Private Sub ws_DataArrival(ByVal bytesTotal As Long)
Dim filenum As Integer
Dim size() As Byte
ReDim size(bytesTotal)
ws.GetData size
filenum = FreeFile
Open fn2 For Binary As filenum
Put filenum, num, size
num = num + bytesTotal
Close filenum
End Sub

Private Sub ws2_DataArrival(ByVal bytesTotal As Long)
ws2.GetData fn1
fn2 = fn1
sendfile (cd1.FileName)
End Sub

Private Function sendfile(file As String)
Dim filenum As String
Dim i, m As Long
Dim size() As Byte
ReDim size(7168)
filenum = FreeFile
Open file For Binary As filenum
m = 1
i = 1
For i = 1 To LOF(filenum) \ 7168
   complete = False
   Get filenum, m, size
   m = i * 7168
   ws.SendData size
   DoEvents
   While Not complete
   DoEvents
   Wend
Next
 If Int(LOF(filenum)) > Int((LOF(filenum) \ 7168) * 7168) Then
       ReDim size(LOF(filenum) - (LOF(filenum) \ 7168) * 7168)
       Get filenum, m, size
       ws.SendData size
    End If
Close
End Function
2007-12-12 00:57
abc5566
Rank: 1
等 级:新手上路
帖 子:201
专家分:0
注 册:2007-9-15
收藏
得分:0 
帮帮忙啊,很急啊
2007-12-12 23:56
快速回复:[求助]我的文件传送程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021945 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved