Creating a function
Most programs will need to execute code from different NAV objects. This code is contained in functions. This recipe will show you how to create a function and explain what functions are in more detail.
How to do it...
Create a new codeunit from Object Designer.
Add a function called
CountToN
that takes an integer parameter, n.Add the following local variables
Name
Type
I
Integer
Add the following code to your function:
FOR i := 1 TO n DO MESSAGE('%1', i);
Add the following code to the
OnRun
trigger of the codeunit:CountToN(3);
Save and close the codeunit.
When you run the codeunit you will see several windows like the following screenshot:
How it works...
By creating a function we can reference multiple lines of code using one easy-to-understand name. Our function is called CountToN
and takes an integer "n" as a parameter. This function will display a message box for every number ranging between one and the number that is passed to the function.
There's more...
Proper...