473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Prob with delay timer

My program takes in a key pressed value from the main routine and
based on the key pressed, it selects the command to be executed. The
problem I have is in creating a delay timer so that a message appears
on my screen for only one second. The condensed code is as follows:

#include <sys\timeb.h>
#define DELAY_1SEC 1000 // in millisec

void Scan_Menu_Keys(int key_press)
{ switch(key_press){
case 1: Execute1stCommand(); break;
case 2: Start_Timer();
while (!Timer_Expired(DELAY_1SEC))
strcpy(CG_ScreenKeyboard.Screen, "Display Message");
Clear_Screen();
break;
default: break;
}
}

void Start_Timer(){
ftime(&start_time); // ftime is function defined in sys\timeb
}

int Timer_Expired(){
ftime(&current_time);
time_diff = (int) (1000.0*(current_time.time - start_time.time) +
(current_time.millitm - start_time.millitm));
return (time_diff >= DELAY_1SEC);
}

The problem I ran into was that the timer would wait for one second
before displaying the message "Display Message". Effectively, that
meant the message never displayed because when it got out of the 1
second delay loop, the screen was cleared. I would love to get
suggestions on why this delay loop is not be executing the command
within the loop and any alternative methods to achieving the same
results.

Thanks in advance!

LYN
Jul 22 '05 #1
2 2252

"lynology" <ya*********@lmco.com> wrote in message
news:1b**************************@posting.google.c om...
My program takes in a key pressed value from the main routine and
based on the key pressed, it selects the command to be executed. The
problem I have is in creating a delay timer so that a message appears
on my screen for only one second. The condensed code is as follows:

#include <sys\timeb.h>
#define DELAY_1SEC 1000 // in millisec

void Scan_Menu_Keys(int key_press)
{ switch(key_press){
case 1: Execute1stCommand(); break;
case 2: Start_Timer();
while (!Timer_Expired(DELAY_1SEC))
strcpy(CG_ScreenKeyboard.Screen, "Display Message");
Clear_Screen();
break;
default: break;
}
}

void Start_Timer(){
ftime(&start_time); // ftime is function defined in sys\timeb
}

int Timer_Expired(){
ftime(&current_time);
time_diff = (int) (1000.0*(current_time.time - start_time.time) +
(current_time.millitm - start_time.millitm));
return (time_diff >= DELAY_1SEC);
}


Think about the above function. What happens if (say)

current_time.time = 1000000
current_time.millitm = 10

start_time.time = 999999
start_time.millitm = 100

I can't answer that question because you are using non-standard C++ (ftime),
but your method of working out the difference between two times may be
incorrect (I think it depends on whether millitm is a signed or unsigned).

john
Jul 22 '05 #2
lynology wrote:
The
problem I have is in creating a delay timer so that a message appears
on my screen for only one second.
case 2: Start_Timer();
while (!Timer_Expired(DELAY_1SEC))
strcpy(CG_ScreenKeyboard.Screen, "Display Message");
Clear_Screen();
Timer_Expired() is called with one argument. Whether this compiles,
depends on a previous declaration (which you `condensed out'). But
surely, it won't link with your definition below.
I would love to get
suggestions on why this delay loop is not be executing the command
within the loop
Presumimng, that the while-condition is true for exactly one second,
there will be many, many strcpy() executions in this time (depending on
your CPU speed). But I can't see a single _output_ statement. Is there
some hidden magic in writing to CG_ScreenKeyboard.Screen?
and any alternative methods to achieving the same
results.


Please consult the documentation of CG_ScreenKeyboard. This is not a
standard C++ class, so I'm afraid, that nobody here can help you.
Ralph

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: M.L. | last post by:
Hi NG, I hope someone in here is able to help me in this matter. The problem: I have created a Javascript drop-down menu which expands when moving the mouse into a tablecell (calls my Expand()...
2
by: Mark | last post by:
Anyway to have a switchboard form open about 10 seconds after the database comes up? Right now it opens when the database starts up but now I need the switchboard form to open about 10 seconds...
1
by: lynology | last post by:
My program takes in a key pressed value from the main routine and based on the key pressed, it selects the command to be executed. The problem I have is in creating a delay timer so that a message...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
11
by: Maheshkumar.R | last post by:
Hi groups, How i can introduce some milliseconds delay in application. How i can do achieve this... let me clearly say... (1) I'm displaying slices of medical images. For framerate - for...
10
by: AmitTrehan | last post by:
hi friends, I want to know how can we insert delay in vb.net like..... i want to show two strings on same label first one string then break of 5 secs and then second string how can i acheive...
18
by: Max | last post by:
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep...
1
by: David Veeneman | last post by:
I want to introduce a one-second delay into the MouseHover event of a label. In other words, I want the user to have to hover over a label for one second before the label's MouseHover event...
9
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.