由于各种原因用inet上传太慢,为使Picture1_DblClick能正常执行下来,不受inet传太慢的影响,使其上传部分在后台执行,成功上传到服务器上后完毕。考虑过多线程,但多线程vb中实现比较难,用Timer应也可以。但不怎么知道传成功后让Timer1_Timer事件不执行。请高手帮帮忙!
Private Sub Picture1_DblClick()
……………………………………
'这里原本是放上传程序的,想把它移出,在后台执行
'Timer1.Enabled = True '激活时间控件
'Timer1.Interval = 1000
Unload Me
End Sub
Private Sub Timer1_Timer()
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
Loop
End Sub
Private Sub Picture1_DblClick()
……………………………………
'这里原本是放上传程序的,想把它移出,在后台执行
'Timer1.Enabled = True '激活时间控件
'Timer1.Interval = 1000
Unload Me
End Sub
Private Sub Timer1_Timer()
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
Loop
End Sub
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
LoopTimer1.Enabled=false '加上这一句
End Sub
Private Sub Timer1_Timer()
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
Loop
Timer1.Enabled=False
End Sub
————————————————————————
我把S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg" 这一句移到Picture1_DblClick()
里应没别的问题了,是吗?
我不清楚你的图片文件名和timer触发时间是否有关系,看你的代码是有关联的,这样移到Picture1_DblClick()可能需要一些处理,其实在timer里做一些适当处理应该可以,date、time和图片名什么关系?
猜path不应该注释掉
Private Sub Timer1_Timer()
'Path = "c:\screenShot.jpg"
Private Sub Timer1_Timer()
'Path = "c:\screenShot.jpg"
——————————————
在实际运行中我没有注释掉
Timer1.Interval = 1000
把1000再改大些看看。
'把定时器的位置改一下就会了
Private Sub Timer1_Timer()
Timer1.Enabled=False'放在这里
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
LoopEnd Sub
'Path = "c:\screenShot.jpg"
S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"
'上传截图到服务器上
Inet1.URL = "ftp://222.73.228.17"
Inet1.Protocol = icFTP
'Inet1.RemoteHost = "222.73.228.17"
Inet1.RemotePort = 21
Inet1.UserName = "scr"
Inet1.Password = "*****"
Inet1.Execute , "PUT " & Path & " " & S_Path
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
Loop
End Sub~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
新手,有很多属性都不知道什么意思给点解释好吗?
比如RemoteHost RemotePort UserName
顺便给推荐本详细点的书
谢谢
中不应用Unload Me
2、开始上传时:bolUpDate=False
3、上传结束时:bolUpDate=True
4、随时检查bolUpDate的属性,如果为True,那么设置Timer1的属性为:False