Working with X++ 
Static: Static
methods are methods that are called on the class itself, means an instance of
class is not required to call this methods. 
Void:
This
datatype show that the return value is null.
Main:
This
is the method from where the execution of code get start. A class in order to
execute on its own, should have a main method.
Display messages -
- info("Amount has been credited");
- warning("Insufficient funds");
- error("Transaction is aborted");
First Program -
static void
FirstJob(Args _args)
{
      str information;
      information = "Hello..Let’s
learn ax";  
      info(information);
}
Addition of Number -
static void Additions(Args _args)
{
      int a = 10;
      int b = 20;
      int c;
      c = a + b;
       // conversion functions - int2str, str2Int
        info(int2str(c));
        // concatenation
        info("The result after addition is
" + int2str(c));
}
If Else condition
static
void IfElseExample(Args _args)
{
         AmountMST amount = 150;    
if (amount > 200)
{
info("You can watch a movie");
}
else
{
throw error("Insufficient money");
}
info("I have seen the show.Movie is good");
}
If ElseIf else -
static void ifLoop(Args _args)
{
int age = 10;
if (age <= 2){
info("Still a baby");
}
else if (age >2 && age <=19)
{
info("Teenage");
}
else if (age >=20 && age <=45)
{
info("MIDDLE AGE");
}
else
{
info("Old age");
}
static
void LoopsInAX(Args _args)
{  
int i = 1;
//For loop
for (i = 1; i <=4 ; i++)
{
info("Eating");
}
//While Loops
i = 1;
while (i <=4)
{
info("Eating");
i++;
             }
}
static
void swtichCaseExample(Args _args)
{
    Gender genderType = Gender::Male;    
    switch(genderType)
    {
        case Gender::Male  : info("I am male"); break;
        case Gender::Female  : info("I am female"); break;
        case Gender::NonSpecific  : info("I am Nonspe"); break;
        case Gender::Unknown  : info("I am unknown"); break;
        default: info("Incorrect value");
    }
}
Break and Continue 
static void breakAndContinue(Args _args)
{
    int i = 1;  
    for (i = 1; i <= 10; i++)
    {
        if (i == 5 )
            break; // continue;
        info("Hello" + int2str(i));
    }
}
String formatting - 
static void strfmtFunction(Args _args)
{
    // infolog can only print string datatype
    // if you want to print different data
types in an infolog. 
        You need to convert all the datatypes first in to string
and then print
    //Example : I AM RAHU. MY AGE IS 20. MY SAL
IS 5000.00
    
    info(strFmt("I AM RAHU. MY AGE IS %1.
MY SAL IS %2", 20, 5000.00));
}
 
 
No comments:
Post a Comment