Results 1 to 7 of 7

Thread: GetTickCount timer, I need a 'DoEvents' or something

  1. #1

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720

    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);
    
    }
    asdf

  2. #2
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    That's because Temp is never greater than (Lasttime + Delay).

  3. #3

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    ? 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;
    asdf

  4. #4
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    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.

  5. #5

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    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"
    }
    asdf

  6. #6
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    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.

  7. #7

    Thread Starter
    Fanatic Member scr0p's Avatar
    Join Date
    Oct 2002
    Location
    VA
    Posts
    720
    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.
    asdf

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