Coding HELP!! Please

 

Why does this not work?

int Y;
if(PERIOD_CURRENT==PERIOD_M3)
     {
      Y  =  2380;
      Print(Y);
     }
   else
      if(PERIOD_CURRENT==PERIOD_M5)
        {
         Y=1428;
         Print(Y);
        }
      else
         if(PERIOD_CURRENT==PERIOD_M10)
           {
            Y=714;
            Print(Y);
           }
 
Mahir Muhtasim Alam Khan: Why does this not work?

You have not explained what "does not work" means for you! Just saying "does not work" has no meaning as we don't know what you are trying to achieve.

However, assuming you are trying to find out the current period, then just know that PERIOD_CURRENT is only a macro constant, just like PERIOD_M5 or the others. It is not a function or variable.

To get the current period use either the function Period() or the predefined variable _Period like so:

int Y;
if(_Period==PERIOD_M3)
{
   Y  =  2380;
   Print(Y);
}
else
   if(_Period==PERIOD_M5)
   {
      Y=1428;
      Print(Y);
   }
   else
      if(_Period==PERIOD_M10)
      {
         Y=714;
         Print(Y);
      }

I would suggest, however, you use a "switch" statement instead of multiple "if". Something like this:

int Y;

switch( _Period )
{
       case PERIOD_M3:  Y = 2380; break;
       case PERIOD_M5:  Y = 1428; break;
       case PERIOD_M10: Y = 714;  break;
       default:         Y = WRONG_VALUE;
};

Print(Y);

 
Fernando Carreiro #:

You have not explained what "does not work" means for you! Just saying "does not work" has no meaning as we don't know what you are trying to achieve.

However, assuming you are trying to find out the current period, then just know that PERIOD_CURRENT is only a macro constant, just like PERIOD_M5 or the others. It is not a function or variable.

To get the current period use either the function Period() or the predefined variable _Period like so:

I would suggest, however, you use a "switch" statement instead of multiple "if". Something like this:

Thank You, i tested it and It was just what i was looking for,

 
Mahir Muhtasim Alam Khan #: Thank You, i tested it and It was just what i was looking for,

You are welcome!

Reason: