By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,302 Members | 1,760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,302 IT Pros & Developers. It's quick & easy.

How to looping with Timer?

P: 1
Dear all,
I am a student making a MS Form application in C++. I would ask a question about "Timer". Sample code which I am developing is below.

private: System::Void buttonStart_Click(System::Object^ sender, System::EventArgs^ e){
for (int i=1; i<=10; i++){
String^ strValue;
FunctionName(&strValue);
int interval=1000; // time interval of looping equal to 1s
SetTimer(timer1, interval, NULL);
do {
this->textBox->Text = strValue;
}
while(TimerFlag = 0);
TimerFlag = 0;
}

private: System::Void FunctionName(String^ *strValue){
*strValue = "Something which could change in each time of above looping";
}

private: System::Void OnTimer(int timerId){
if(timerId = 1){
TimerFlag = 1;
HWND hwnd = NULL;
KillTimer(timer1);
}
}
...

Compiling errors are
1. SetTimer doesn't take 3 arguments
2. Kill timer doesn't take 1 arguments

How should I input the arguments and how should I correctly looping with 1s interruption? Please help me!

Thank you very much in advance.

Davaa
Jul 9 '08 #1
Share this Question
Share on Google+
2 Replies


gpraghuram
Expert 100+
P: 1,275
If you are free to use any libraries then try to use ACE.
It has a timer also in it...

Raghu
Jul 9 '08 #2

hdanw
P: 61
Expand|Select|Wrap|Line Numbers
  1. while(TimerFlag = 0);
This will always fail to execute as

Expand|Select|Wrap|Line Numbers
  1. TimerFlag = 0
will always be false.

Expand|Select|Wrap|Line Numbers
  1. if(timerId = 1)
This line isuseless unless you actually want to assing 1 to timerId, but the braces and the if are not neccessary.

I think you stick with the basics for now.

You need to get with your instructor and let him or her know you need some one on one time with a tutor.

Somethings are quicker when your not strugling with the slow communication of the internet.

Also, a tutor can see whether this code took you a few seconds to write or a few days, and they can imediately address the areas that you should be focusing on.

Expand|Select|Wrap|Line Numbers
  1. if( SomeValue == 1) 
Notice the second '='?
Jul 12 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.