Results 1 to 9 of 9

Thread: Timer question [SOLVED, thank you]

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Timer question [SOLVED, thank you]

    Ok, I have a check box, and when that checkbox is enabled, it autochecks my E-mail every 5 minutes. I multiply that by 60, and then multiply it again by 1000 to get the number of milliseconds in 5 minutes, and use the total as the timer interval.

    5 * 60 = 300
    300 * 1000 = 300000

    However, when I run the program, I get an error message saying that the interval variable is invalid, I guess the value is too large for the timer to handle, so I tried using it as a countdown timer, counting down from 300 seconds.

    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Dim Seconds As Integer
    3.     Seconds = 300
    4.     Do While Seconds > 0
    5.         Seconds = Seconds - 1
    6.     Loop
    7.     If Seconds = 0 Then
    8.         Call CheckMail
    9.         Seconds = 300
    10.     End If

    While testing the code, I found that the program will execute CheckMail immediately, without making any calls to the timer process. I had a small bit of code that would have fixed this problem. It's inside my "Learn Visual Basic 6" E-book, and I think it's covered in Chapter 2 or 3, I can't remember which. However, I don't have it readily available to me, as it's on a CD that my dad uses for work, and I can't remember it offhand. Guess it kinda serves me right for allowing my dad to burn my CD's, he also burns other stuff that he wants/needs.
    Last edited by hothead; Nov 27th, 2002 at 04:26 PM.

  2. #2
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Here's something you may can adjust to do what you need:
    VB Code:
    1. 'In Form_Load:
    2.  
    3. Private Sub Form_Load()
    4. 'Set Text1 to the current time
    5. Text1.Text = Time()
    6. End Sub
    7.  
    8. 'In Time1_Timer
    9.  
    10. Private Sub Timer1_Timer()
    11. 'Timer interval set to 1000 will execute every second or what ever you want
    12.  
    13. 'Everytime the timer fires get the difference between the current time and the time saved in Text1
    14. diff = TimeValue(Text1.Text) - TimeValue(Now())
    15.  
    16. 'Set the Minute difference to a variable
    17. mindiff = Minute(diff)
    18.  
    19. 'Check if it has been five minutes
    20. If mindiff = 5 Then  
    21.     MsgBox "Checking Email now!"
    22.     Text1.Text = Time()    '<--Reset Text1 to new time here
    23. End If
    24.  
    25. End Sub
    Sorry if this looks crude but I do not have VB here...

    Hope this helps

    JO
    Last edited by joltremari; Nov 27th, 2002 at 04:38 PM.
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    That code gives me a type mismatch.

    It doesn't matter now, my dad's back with my CD. Thanks for trying.
    Last edited by hothead; Nov 27th, 2002 at 04:25 PM.

  4. #4

  5. #5

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    It's gotta be a date?

    All I got in there is a time.

    PSC appears to be online again, I'll see if they got something that can help me.

  6. #6

  7. #7

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    It is a time value from tmrCurrentTime.

    Here's the code from tmrCurrentTime in case you need it It's very simple actually, just a single line:

    VB Code:
    1. Private Sub tmrCurrentTime_Timer()
    2.     Text1.Text = "Current time is " & Format(Time, "hh:mm ampm")
    3. End Sub

    That displays only hours and minutes.

    How would I get the program to take the current time, and in exactly 5 minutes after that, execute the CheckMail function?

  8. #8

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Hey, I got it to work using another method.

    VB Code:
    1. Private Sub tmrCheckMail_Timer()
    2.     Static Seconds As Integer
    3.     Set Win32Script = CreateObject("WScript.Shell")
    4.     Interval = Win32Script.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Gitmail\Main Settings\Check Interval")
    5.     Seconds = Seconds + 1
    6.     Text1.text = Seconds
    7.     If Seconds = Interval Then
    8.         Call mnuGetAll_Click
    9.     End If
    10. End Sub

    This was what I was talking about in my first post on this thread. I kept getting bugs in the code like the following:

    1. The timer wouldn't work unless I declared the Seconds variable as Static

    2. I can't change a static variable to reset itself when it reaches the value specified in the Interval variable, which in this case, is 300. Of course I had to shorten it a bit for testing purposes.

    There's just one problem: The event will only trigger once. I need it to trigger after 300 seconds, then reset, then trigger again after another 300 seconds, then reset, and so on.

  9. #9
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Hi, Glad you got it working. I just wanted to tell you that the reason the code I gave you didn't work was because in your Text1.Text you have the string "Current time is " and there can only be date/time in that text box for the code to work. If you were to put a label beside the text1 box that said "Current time is:" and only have Text1.Text = Format(Time, "hh:mm ampm") in Text1.Text then it would work and it would execute every 5 min.

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width