由于各种原因用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

解决方案 »

  1.   

    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
          LoopTimer1.Enabled=false     '加上这一句
    End Sub
      

  2.   


    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
      

  3.   

     让Timer1再执行的方法是:Timer1.Enabled=True
      

  4.   

    S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"这种写法有问题,有时系统正在做其他的,timer不能触发就会错过时间
      

  5.   

    lz的逻辑貌似有点混乱,看代码好像每次timer触发发送的是不一样的图片,传成功后timer不需要停止,等待下一次触发传下一个图片,这样就可以了
      

  6.   

    谢谢jhone99的提醒
    ————————————————————————
    我把S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg" 这一句移到Picture1_DblClick()
    里应没别的问题了,是吗?
      

  7.   

    有一个问题,就是如果上传要5秒,没有在1秒内上传到服务器,也就是过了一秒后,此时没上传完会执行Timer1_Time()里面的事件吗?
      

  8.   


    我不清楚你的图片文件名和timer触发时间是否有关系,看你的代码是有关联的,这样移到Picture1_DblClick()可能需要一些处理,其实在timer里做一些适当处理应该可以,date、time和图片名什么关系?
      

  9.   

    其实是这两张图(图片是一样的)一张是存在本地的就是'Path = "c:\screenShot.jpg",然后把本地的这个图传到服务器上去,到服务器上不能叫相同的名字,所以就有screenShot.jpg这张图按时间重命名后再传到服务器上。我再想了一下S_Path = Format(Date, "YYYYMMDD") & Format(Time(), "HHMMSS") & ".jpg"放在Timer1_Time()里没有问题的
      

  10.   

    上传代码移到Timer1_Time()后,不知什么原因现在图片根本传不到服务器上去了,急急急
      

  11.   


    猜path不应该注释掉
    Private Sub Timer1_Timer()
      'Path = "c:\screenShot.jpg"
      

  12.   

    猜path不应该注释掉
    Private Sub Timer1_Timer()
      'Path = "c:\screenShot.jpg" 
    ——————————————
    在实际运行中我没有注释掉
      

  13.   

    间隔太小了,1秒钟FTP地址探测结果可能都没有返回呢。
    Timer1.Interval = 1000
    把1000再改大些看看。
      

  14.   


    '把定时器的位置改一下就会了
    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
      

  15.   

    用timer其实也达不到你说的“后台运行”要求的,建议你可以做成一个单独的exe文件,在这个程序中将要上传的参数传给小的exe文件,让他执行上传,执行完毕就退出。
      

  16.   

    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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    新手,有很多属性都不知道什么意思给点解释好吗?
    比如RemoteHost   RemotePort  UserName
    顺便给推荐本详细点的书
    谢谢
      

  17.   

    Picture1_DblClick()
    中不应用Unload Me
      

  18.   

    我调试了一下,是这样的,达不到后台运行的要求,我是做一个截屏activex控件,再传用一个exe来传文件不可能的呀,有别的办法。非要用多线程吗?
      

  19.   

    我认为,上传代码不应写在 Timer1_Timer事件中,很多不便都是因为上传代码写在 Timer1_Timer事件中造成的,难道上传代码不写在 Timer1_Timer事件中就不行吗?
      

  20.   

    1、定义一个布尔变量:bolUpDate
    2、开始上传时:bolUpDate=False
    3、上传结束时:bolUpDate=True
    4、随时检查bolUpDate的属性,如果为True,那么设置Timer1的属性为:False