Artimetic operations with form field values

i have created there button ADD,Sub,MUL

so if i cleick on add it should take field 1 and 2 values and perform addition add show result in field3

Action should perform from class ( in class different methods (ADDition ,substraction,multplfor

how can i get the value of that field to class to perform addition

You again forgot to attach a tag with the version. Please do it now, so we don’t suggest a solution that isn’t applicable to your version of AX.

Also, what can you tell us about the fields? Are those table fields? You seem to be building a calculator, therefore I wouldn’t use a table, to be honest, unless that’s something your want to do for training purposes.

Title changed from “created a form with 3 fiedls (field1 ,fied2 ,fields3) need to perform Addition ,substraction(artimetic operation)” to “Artimetic operations with form control values”.

D365

not table fields

Okay, thank you for letting us know what it isn’t. Could you also please tell us what it is? Unbound controls? Or you don’t know yet what to use and you want our help with the overall design?

I attached the version tag (D365FO) for you.

unbound contorl

Well, it seems you don’t want to share much information with us. Obviously we can’t address your particular problem unless you actually describe it.

Anyway, here is the simplest possble approach:

  • Set AutoDeclaration properties of your controls to Yes.
  • Add buttons for operations, such as Add, and override clicked()
  • Perform the operation and set the value of the result field. For example:
public void clicked()
{
    real result = Field1.realValue() + Field2.realValue();
    Field3.realValue(result);
}

When you understand how to do this simplest thing, you can improve it. For example, you can create a class method accepting two arguments and return a result, and call this method from clicked().

public void clicked()

{
super();
FormInt64Control valueA = element.design().controlName(formControlStr(KalOpertorform, Add));
FormInt64Control valueB = element.design().controlName(formControlStr(KalOpertorform, sub));
FormInt64Control valueC = element.design().controlName(formControlStr(KalOpertorform, result));
int64 valueOfA = any2Int64(valueA.valueStr());
int64 valueOfB = any2Int64(valueB.valueStr());
// int64 Multiplication = valueOfA * valueOfB;

valueC.value();
}

this is what in clicked fucntion but how to get value from clicked to class and return back answer again to click

this is what i actually want

Your code is over-complicated. Let me simlify it for you:

public void clicked()
{
	super();
	
	int64 multiplication = Add.value() * Sub.value();
	result.value(multiplication);
}

Note that the names look wrong to me. Didn’t you intend to use names Add and Sub for buttons?

By the way, please always use Insert > Insert code to paste source code, as I did.

There are many ways how you could design the class. For example, you could use a static method for each operation:

int64 multiplication = Calculator::multiply(Add.value(), Sub.value());
result.value(multiplication);

so how to get value to class,

and how to call class in clicked

Please see the end of my previous reply.

that last need to placed in class

What what would be the point of doing that? The code is using form controls, therefore you would have to pass references to all form controls to the class, and then what would be the benefit?

As I said, there are many ways how you can designing classes for this purpose. I can’t tell which design would be the best for your requirements, because you’ve never shared them with us.

to be clear

please write the code for class

What’s the exact problem? You don’t know how tio create a class? Or how to implement the method?

It’s absolutely trivial:

class Calculator
{
	public static int64 multiply(int64 _value1, int64 _value2)
	{
		return _value1 * _value2;
	}
}

so now how can i retun result to clicked method so that it print in result field

You can see it in code I gave you before. Please look at it again.

my requirment is

when add button clicked it should call additon method in class artimetic and it add and return result of addition to result field back

So what’s the problem? I showed how to implement a multiplication and your case is almost identical; you’ll just use + operator instead of *.

my problem is how to call additon method from clicked