|
Hello,
How can I call a function each five minutes?
explanation:
WinMain{
...
Each5Minutes(MyFunction(...));
}
thanks in advance
christian
|
|
|
|
|
Create a one-minute timer with SetTimer() . Each time the timer procedure, or the WM_TIMER message handler, is called, increment a counter. Once that counter reaches five, you know that at least five minutes has elapsed. Be sure to reset the counter to zero!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Create a one-minute timer with SetTimer()...
And why not just create 5-minute timer?
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Last time I checked, the maximum value that could be passed to SetTimer() was 65536, which is about 65 seconds.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
DavidCrow wrote:
the maximum value that could be passed to SetTimer() was 65536
Correct me if I'm wrong:
UINT_PTR SetTimer(
...
UINT uElapse, // time-out value (milliseconds)
...
);
UINT is an unsigned 32 bit value (in Microsoft VC++ 6 at least). So it's max value is 2^32 - 1 = 4,294,967,295. These represent milliseconds. Which means over 4 million seconds, which means over 700,000 minutes, which means over 11,000 hours, which means over an year...
So 5 minutes is ok, I guess...
|
|
|
|
|
Anonymous wrote:
So it's max value is 2^32 - 1 = 4,294,967,295. These represent milliseconds. Which means over 4 million seconds, which means over 700,000 minutes, which means over 11,000 hours, which means over an year...
Close. It is actually over 4 billion seconds, which is roughly 49.7 years. Last I remember, anything over 65,536 would not work. I just tried it with 90,000 and it worked as expected. Go figure!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
|
Another solution is a timer queue timer.
Kuphryn
|
|
|
|
|
Another solution is a timer queue timer.
Could you please explain what you mean here. Thnx
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Check out CreateTimerQueue() and CreateTimerQueueTimer() . The timers are lightweight objects that enable you to specify a callback function to be called when the specified due time arrives.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
That's helpfull: supported only on 2000 and up...
Thnx
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
You can also use GetTickCount()
DWORD dwBeginOf5Secs = GetTickCount();
while (TRUE)
{
if (GetTickCount() - dwBeginOf5Secs > 5000)
{
dwBeginOf5Secs = GetTickCount();
}
else
Sleep(100);
}
Peter Molnar
|
|
|
|
|
I am reading in CString values from a file and atoi-ing them. Docs say it returns 0 if the string cant be converted to a number (though the example there says atoi("5 cars") returns 5 -- I thought it would return 0 ???) Confused about this.
The other thing is that I might have a CString "0". If atoi returns 0 in this case, then its not signalling an error. So would I treat the case of strings like "0" separately?
Thanks,
ns
|
|
|
|
|
atoi() would return 0 for "cars 5" since it found no numbers before it found a non-number. In other words, it converts all numbers up to the first non-number encountered.
Differentiating between the return values of atoi("0") and atoi("T") sounds like a design issue. What is the format of the incoming data?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
The data has been writeString--ed to a file with a %d format.
So I read it back in later and want to make sure someone didnt inadvertently change what should be a numerical entry in the input file, into a alphabetical entry.....so I was going to use atoi to check the readstring-ed CString......
Thanks,
ns
|
|
|
|
|
So your file should look like:
123
456
004
991
...
and you want to ensure that someone hasn't changed it to:
07b
1c8
004
3df
...
Is that an accurate assesment? If so, you'll need to employ ReadString() to read each line from the file and parse the data yourself, something like:
CString strLine;
while (...)
{
file.ReadString(strLine);
if (! IsAllNumbers(strLine))
AfxMessageBox(...);
}
bool IsAllNumbers( LPCSTR lpszData )
{
while ('\0' != *lpszData)
{
if (isdigit(*lpszData))
lpszData++;
else
return false;
}
return true;
}
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thank you so much! Its exactly what the scenario is and your resolution works really well! I appreciate having this snippet of code to "import" into my project.
ns
|
|
|
|
|
atoi starts translation first by removing seperator characters(like space) from the string, looking for the first character. if it is a digit, it starts translating it into an integer, but if not, it returns zero.
you can use it like this:
LPSTR ss="4 cars";
int x=atoi(ss);
if(x==0 && strcmp(ss,"0")){
// the input is probably not a real zero,
// it's an error
}
|
|
|
|
|
Actually it would be better to use strncmp instead of strcmp because then you specify the number of characters to compare so it would return correctly if the string contained "0 cars" also you would want to trim out the spaces in the string first before the compare in case you had a string " 0 cars" so that it would return correctly as well.
|
|
|
|
|
Appreciate the explanation and the nifty way to handle it.
Many thanks,
ns
|
|
|
|
|
I usually use isdigit() to test for such things.
Calling a function that carries out an operation that you have no intent on using just to see if it returns an error isn't typically considered good design.
|
|
|
|
|
For example:
'D:\Documents and Settings\Grrrr\My Documents'
In VC++6.0, which function or API or Class can do this?
Thanks a lot...
|
|
|
|
|
use SHGetSpecialFolderPath
|
|
|
|
|
This method is the simplest method??
Just now, I have read this function in MSDN.
I found it use Shell...
I thought there have a simple mothod, I thought we can get the path-name
direct, use a API. as 'GetSystemDirectory'.
I'm sorry.perhaps i am wrong.
|
|
|
|
|