Solved

how to extend the funtion Timer?

Posted on 2007-12-01
14
240 Views
Last Modified: 2010-04-30
Hello Experts,
how to extend the Timer function over 60000 milliseconds??
I need to to extend the time of r one of my function
0
Comment
Question by:aitsu01
  • 7
  • 6
14 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20387740
what I do is this:
have the timer interval set to 1000 (1 second)
and have 1 form-level variable set initially to the number of seconds you want to wait.
the timer interval would then decrease that variable, and when 0, run the procedure/work to do, and resets the interval counter.


Private gTimerInterval as Integer 
Private Sub Timer1_Timer()
  Timer1.Enabled = false
  Timer1.Interval = 1000 
  if gTimerInterval <= 0 then
    gTimerInterval = 100  ' set the interval in seconds again
    DoWork()              ' run the code you want to run in the interval  
  else
    gTimerInterval = gTimerInterval -1 
  end if 

  Timer1.Enabled = true
End Sub

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 20388363
Here is another very similar approach using a Date variable...

Option Explicit
 
Private minutes As Integer
Private targetTime As Date
 
Private Sub Form_Load()
    Timer1.Enabled = False
    minutes = 11
    SetNewTargetTime
    Timer1.Interval = 1000
    Timer1.Enabled = True
End Sub
 
Private Sub SetNewTargetTime()
    targetTime = DateAdd("n", minutes, Now)
End Sub
 
Private Sub Timer1_Timer()
    If Now > targetTime Then
        Timer1.Enabled = False
        
        ' do something here...
        Debug.Print "something"
                
        SetNewTargetTime
        Timer1.Enabled = True
    End If
End Sub

Open in new window

0
 

Author Comment

by:aitsu01
ID: 20388825
Hello angellll,
the value of the gTimerInterval = 100 ?youe mean 100 seconds or 100 milliseconds?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:aitsu01
ID: 20388830
Hello idle mind;
refered to targetTime = DateAdd("n", minutes, Now)
 what stands the "n" for?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20388859
>the value of the gTimerInterval = 100 ?youe mean 100 seconds or 100 milliseconds?

would mean 100 seconds, as the timer1.interval is set to 1000 (means 1 second).


>refered to targetTime = DateAdd("n", minutes, Now)
> what stands the "n" for?
n stands for minutes, see the reference:
http://msdn2.microsoft.com/en-us/library/cb7z8yf9.aspx
0
 

Author Comment

by:aitsu01
ID: 20389008
if i have two timer how can i solve it??
for example with timer1 and timer2
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20389031
what are the 2 timers doing?
0
 

Author Comment

by:aitsu01
ID: 20389061
timer1 upload my file.txt to my ftp web space
timer2 delete the uploaded text file and load the form1

see below here for the code:
Private Sub Timer1_Timer()
   Dim host_name As String
    Dim time As String 
   Dim user As String
   Dim directory As String
  
   
   
   Unload form1
 
   'On Error Resume Next
     Texttime = Now
    Enabled = False
    MousePointer = vbHourglass
    txtResults.Text = "Working"
    txtResults.SelStart = Len(txtResults.Text)
    DoEvents
 
  
    host_name = txtHost.Text
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name
    inetFTP.URL = host_name
 
    inetFTP.UserName = txtUserName.Text
    inetFTP.Password = txtPassword.Text
    time = CStr(Time)
    directory = mydirectoryfile
    inetFTP.Execute , "mkdir " & directory
    Pause 1000 'give time for the process completing operation
    inetFTP.Execute , "cd " & directory
    Pause 1000
    On Error Resume Next
    
    inetFTP.Execute , "Put " & _
          "c:\myfile.txt" & " & "_" & time
End Sub
 
 
 
 
Private Sub Timer2_Timer()
 
 Kill "c:\myfile.txt"
 Load form1
   
End Sub

Open in new window

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20389067
why don't you kill and load form1 at the end of the timer1 ?
0
 

Author Comment

by:aitsu01
ID: 20389093
an eror will appear
i used the second timer just to get a little more time to complete the operation
anyway let me try again with your suggestion i resumed amny time that code so maybe now it will works
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20389103
>an eror will appear
would be interesting to learn that error.

anyhow, how much time between that last line and the additional steps?

it would go like this:

Private gTimer2 as Integer
 
Private Sub Timer1_Timer()
   Dim host_name As String
    Dim time As String 
   Dim user As String
   Dim directory As String
  
   Timer1.enabled = false 'stop this timer.
   
   Unload form1
 
   'On Error Resume Next
     Texttime = Now
    Enabled = False
    MousePointer = vbHourglass
    txtResults.Text = "Working"
    txtResults.SelStart = Len(txtResults.Text)
    DoEvents
 
  
    host_name = txtHost.Text
    If LCase$(Left$(host_name, 6)) <> "ftp://" Then host_name = "ftp://" & host_name
    inetFTP.URL = host_name
 
    inetFTP.UserName = txtUserName.Text
    inetFTP.Password = txtPassword.Text
    time = CStr(Time)
    directory = mydirectoryfile
    inetFTP.Execute , "mkdir " & directory
    Pause 1000 'give time for the process completing operation
    inetFTP.Execute , "cd " & directory
    Pause 1000
    On Error Resume Next
    
    inetFTP.Execute , "Put " & _
          "c:\myfile.txt" & " & "_" & time
 
   gTimer2 = 100 'wait 100 seconds
   Timer2.enabled = true  'and start waiting...
End Sub
  
 
Private Sub Timer2_Timer()
 if gTimer2 <= 0 then 
    Timer2.enabled = false
    Kill "c:\myfile.txt"
    Load form1
 end if
 gTimer2 = gTimer2 -1 
End Sub

Open in new window

0
 

Author Comment

by:aitsu01
ID: 20391764
it appears an runtime error 70
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 20391957
70 = permission denied... for example, a file is still open/locked by another process...

I assume on the line where you try to "kill" (delete) the file?

then, you could rerun the timer2 on (any) error that happens during "killing" the file
Private Sub Timer2_Timer()
 if gTimer2 <= 0 then 
    Timer2.enabled = false
  on error resume next
 
    Kill "c:\myfile.txt"
    if err.number <> 0 then
      Timer2.enabled = true
      gTimer2 = 100
      exit sub 
    end if    
 
    Load form1
 end if
 
 gTimer2 = gTimer2 -1 
End Sub

Open in new window

0
 

Author Comment

by:aitsu01
ID: 20410315
Hello  angellll,
how about the property of the timer 1 and timer 2?
i should set both to o millisecond or 1000 milliseconds?
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question