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...

No comments:

Post a Comment