|
-
Nov 27th, 2002, 02:32 PM
#1
Thread Starter
Fanatic Member
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:
Private Sub Timer1_Timer()
Dim Seconds As Integer
Seconds = 300
Do While Seconds > 0
Seconds = Seconds - 1
Loop
If Seconds = 0 Then
Call CheckMail
Seconds = 300
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.
-
Nov 27th, 2002, 03:05 PM
#2
Fanatic Member
Here's something you may can adjust to do what you need:
VB Code:
'In Form_Load:
Private Sub Form_Load()
'Set Text1 to the current time
Text1.Text = Time()
End Sub
'In Time1_Timer
Private Sub Timer1_Timer()
'Timer interval set to 1000 will execute every second or what ever you want
'Everytime the timer fires get the difference between the current time and the time saved in Text1
diff = TimeValue(Text1.Text) - TimeValue(Now())
'Set the Minute difference to a variable
mindiff = Minute(diff)
'Check if it has been five minutes
If mindiff = 5 Then
MsgBox "Checking Email now!"
Text1.Text = Time() '<--Reset Text1 to new time here
End If
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
-
Nov 27th, 2002, 04:22 PM
#3
Thread Starter
Fanatic Member
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.
-
Nov 27th, 2002, 04:28 PM
#4
Probably because whatever is in Text1.Text is not being recognized as a date. What is the avlue you are using?
-
Nov 27th, 2002, 05:08 PM
#5
Thread Starter
Fanatic Member
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.
-
Nov 27th, 2002, 06:21 PM
#6
I'm sorry I should have said date or time. What exactly is the value you are using?
-
Nov 27th, 2002, 08:07 PM
#7
Thread Starter
Fanatic Member
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:
Private Sub tmrCurrentTime_Timer()
Text1.Text = "Current time is " & Format(Time, "hh:mm ampm")
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?
-
Nov 27th, 2002, 08:23 PM
#8
Thread Starter
Fanatic Member
Hey, I got it to work using another method.
VB Code:
Private Sub tmrCheckMail_Timer()
Static Seconds As Integer
Set Win32Script = CreateObject("WScript.Shell")
Interval = Win32Script.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Gitmail\Main Settings\Check Interval")
Seconds = Seconds + 1
Text1.text = Seconds
If Seconds = Interval Then
Call mnuGetAll_Click
End If
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.
-
Dec 2nd, 2002, 01:33 AM
#9
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|