Monday, 12 October 2015

Creating a simple calculator in AX2012

To design above calculator

1.

 2.
method1:
public class FormRun extends ObjectRun
{
    real r;
    real a;
    str k;
    str s;
    real z;
}

method2:
public void init()
{
    super();
    r = 0;
}

3.Override cilcked method of every button

write below code for numbers from 0 to 9
 void clicked()
{
    super();
    r = 10*r+7;
    k = num2str(r,2,2,1,2);
    disply.text(k);
}

 4.For operators write below code
void clicked()
{
    super();
    s="-";
    a = r;
    r = 0;
    disply.text("-");
}

5.For %
void clicked()
{
    super();
    r = r*100/a;
    K = num2str(r,2,2,1,2);
    disply.text(k);

}


6.For = button write below code
void clicked()
{
    super();

    if(s=="+")
    {
        z = a+r;
        K = num2str(z,2,2,1,2);
        disply.text(k);

    }
    else if(s=="*")
    {
        z = a*r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    else if(s=="-")
    {
        z = a-r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    else if(s=="/")
    {
        z = a/r;
        K = num2str(z,2,2,1,2);
        disply.text(k);
    }
    a = 0;
    r = z;

}
Note: 'disply' is name of stringedit control...

Creation of dynamic timer in AX 2012









1.Create a form
2. Form>design>control>timeedit(Name : realTime)
3.Write form run methods
method1:
void updateRealTime()
{
    realTime.value(timenow());

    // Set a Time Out with the idle flag set to false
    this.setTimeOut(identifierstr(updateRealTime), 1000, false);
}
method2:
void run()
{
    super();
    this.updateRealTime();
}

Note:Here realTime is control name
Refer AOT>Form>tutorial_timer