|
-
Apr 4th, 2003, 09:51 PM
#1
Thread Starter
Fanatic Member
GetTickCount timer, I need a 'DoEvents' or something
This just runs a console window and nothing shows up, no errors.. VS.NET
Code:
#include <windows.h>
#include <iostream.h>
void main()
{
bool OK = 0;
long TEMP = 0;
long LASTTIME=0;
long DELAY = 500;
do
{
TEMP = GetTickCount();
if (TEMP >= LASTTIME + DELAY)
{
cout << "Tick TocK\n";
}
LASTTIME = TEMP;
}while(OK == 0);
}
-
Apr 5th, 2003, 12:08 AM
#2
Hyperactive Member
That's because Temp is never greater than (Lasttime + Delay).
-
Apr 5th, 2003, 09:43 AM
#3
Thread Starter
Fanatic Member
? The temp is the tickCount, it keeps on increasing every 1 ms.. it will be greater every 500ms, that's how the timer works. I fixed my problem, it was because I can't use \n I had to use endl;
cout << "Tick TocK\n";
changed to:
cout < "Tick Tock" << endl;
-
Apr 5th, 2003, 01:51 PM
#4
Hyperactive Member
Your code logic is still flawed
That's because TEMP is always greater than (0 + 500), unless your computer takes less than 500 milliseconds to boot.
-
Apr 5th, 2003, 01:58 PM
#5
Thread Starter
Fanatic Member
No, you are missing the bottom part.
LASTTIME = TEMP;
That will make LASTTIME = to the tickCount, so itll look soemthing like this:
lets say uptime is 1000,
if 1000 > 0 + 500 (if 1000 > 500 then "OK")
{
cout << "OK"
}
if 1000 > 1000 + 500 (if 1000 > 1500 then "500 ms passed, OK")
{
cout << "OK"
}
-
Apr 5th, 2003, 08:55 PM
#6
Hyperactive Member
Code:
TEMP = GetTickCount();
if (TEMP >= LASTTIME + DELAY)
{
cout << "Tick TocK"<<endl;
}
LASTTIME = TEMP;
But the execution time between them (Blue statements) is less than 1 ms before they are assigned a new value again.
I'm running on VS.Net too and it only displays "Tick Tock" once.
-
Apr 6th, 2003, 12:04 PM
#7
Thread Starter
Fanatic Member
tHat code is old sry, the LASTTIME = TEMP;
goes under the cout << inside the if statement, I forgot I changed that in my own code.
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
|