Search code examples
visual-studio-2008if-statementc++-cliintsystemtime

C++/CLI: SYSTEMTIME Programming Error


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!


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();
    }