Page 1 of 1

PostPosted: Wed Nov 30, 2005 12:59 am
by pradip
Hello, i'm newbie in programming.
Does anyone can tell me how to make time in 'real time mode'. I ever use stupid code like this:

main ()
{
int a, b; string s;
graph_on();
title("real time");
text(3, 20, "Time:");

textattr(1,1,0);
do
{
event(10); a=time(2);
s=strright(a,2);
text(25, 20, "\t\t" + time(1) + ":"+s+"");
}
while(b!=5);
}

anyway, it works as a stand alone application. But it doesn't if the code merged into an application. Does anyone tell me a better solution?

PostPosted: Sun Dec 04, 2005 3:59 pm
by dewey
Can you be more specific? What doesn't work?

PostPosted: Mon Dec 05, 2005 1:40 am
by pradip
I mean, when i use CControl to add some button in my program, and i insert my code (time) in somewhere, the button doesn't works.
Because it's seems the code of button (Ccontol) never be executed. I have no idea how to solve it.

PostPosted: Tue Dec 13, 2005 8:07 am
by dewey
You would need to share the code that doesn't work, otherwise no one will be able to help you.

PostPosted: Thu Dec 15, 2005 1:24 am
by pradip
This is my code:

// The real time main (CEditor)

include "Ccontrols.c"

/$The real time controls (CEditor)
Chandle about;

initcontrols()
{
about=Cbutton(3,146,33,12,1,4);
}

initcontents()
{
Csetcontent(about,"About");
}

inititems(){
}

drawcontrols()
{
Cdraw(about);
}

/$ The real time methods (CEditor)
on_about()
{
alert("Example.\n\nReal time.");
}

messageloop()
{
int e;
while(1)
{
e=event(1);
if(Cevent(about,e)) on_about();
}
}

realtime ()
{
int a, b; string s;
text(3, 20, "Time:");
textattr(1,1,0);
do
{
event(10); a=time(2);
s=strright(a,2);
text(25, 20, "\t\t" + time(1) + ":"+s+"");
}
while(b!=5);
}


main()
{
graph_on();
title("The real time");
Cinit();
realtime();
initcontrols();
initcontents();
inititems();
drawcontrols();
messageloop();
}

If compiled, this program does't work properly.

PostPosted: Thu Dec 15, 2005 3:13 pm
by dewey
The problem is that you have two event loops: messageloop() and realtime(), and realtime() never exits since b will never equal 5. You should only be using messageloop() if you want your CControls UI to function.

PostPosted: Fri Dec 16, 2005 1:04 am
by pradip
I see. I need learn more i think