How Do I Simply Execute .NET Code? (Magic xpa 4.x)
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004POi&feoid=00ND0000005rAjf&refid=0EM3z000001re6R)
Magic xpa executes .NET code in the background whenever you use .NET objects. However, you can also execute .NET code directly, giving you more complete control.
![](/PublicKnowledge/servlet/rtaImage?eid=ka23z0000004POi&feoid=00ND0000005rAjf&refid=0EM3z000001re6V)
-
First, create the necessary variables. In this example, there are three: vValue1, vValue2, and vSum. All are Magic xpa Numeric variables.
-
Create a handler where the code will execute. In this example, the event handler executes when the Calculate button is pressed. The event uses Force Exit = Editing, so the field value is stored before the button is pressed.
-
Within the handler, create an Invoke .NET operation. Zoom from the field after .NET.
-
Here you will get an ExecuteDotNetCode window. Fill in the Method Name field with whatever name you want to use.
-
Zoom from the Arguments field. This will open up an Arguments window. Create one line for each of the two input arguments:
-
Press F4 to open up a line.
-
Zoom from the Var field to select the variable (or use an expression from the Exp field).
-
Magic xpa will suggest a .NET type. Accept it or change it to something else.
-
Give the variable a .NET name. Here, NumA and NumB were used.
-
Zoom from the Return Value field, to select the variable that will hold the result. Again the Return Value Type is suggested: you may accept it, or change it.
-
Now, in the .NET Code area, type in your code. In our example,
return NumA + NumB;
was added. Magic xpa will automatically pass NumA and NumB, based on the arguments, and will automatically store the results in the Return Value variable, C.
This is a simple example of .NET code; however, you can use more complex code to do whatever is needed.
The Online and Rich Client Samples projects (program NE06 and RNE06)