Question

I'm trying to make a little alert system to do something (IDK what I want yet) when a certain time arrives. However, I'm getting all these errors when I run that code in a WinForm after some brief changes. But this code (unchanged) worked in my empty project! I have the snippet below:

int checktime ()
{
    SYSTEMTIME time;
    GetLocalTime( &time );
    int hour = time.wHour;
    int minute = time.wMinute;
    if (hour > 12) hour -= 12;
    if hour == 8
    {
        this->progressBar1->PerformStep();
    }
}

As always, I would appreciate any help or suggestions available. Thanks!

Was it helpful?

Solution

if hour == 8

That's not valid C++ or C++/CLI. The parentheses in an if statement are not optional.

And why aren't you using .NET System::DateTime::Now? That whole function could be:

int checktime ()
{
   int hour = System::DateTime::Now.Hour;
   if (hour == 8 || hour == 20)
    this->progressBar1->PerformStep();
}

OTHER TIPS

Use a Timer object to keep track of the passing time.

In the designer, drag a timer over from the toolbox onto your form, or instantiate one in the code. You can set the duration (using the interval member), and with each "tick", the system raises an event, and you can perform an action.

It's nice because it's almost like having another thread keeping track in the background.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top