Showing posts with label C/SIDE Tutorial. Show all posts
Showing posts with label C/SIDE Tutorial. Show all posts

FOR Loop

FOR Loop or FOR Statement In Microsoft Dynamics NAV

Definition

FOR loop is a repetitive statement or loop, is used when we need to execute the code a predetermined number of times. 

FOR Loop in Microsoft Dynamics NAV, C/AL having mainly 2 types

  1. FOR .. TO Loop
  2. FOR .. DOWNTO Loop

FOR .. TO Loop

In the case of FOR .. TO Loop the value checking is incresed format and when the value reach the condition wrong then exit loop.

Syntax of FOR .. TO Loop:

--------------------------------------------------------------

FOR Control Variable :=  Start Value TO End Value

DO Statement

--------------------------------------------------------------

Here Control Variable must be a variable type of Boolean, Date, time or any numeric type. The Start value and End Value must be either expressions of same data type.

For Example:

===========================================

FOR i :=1 TO 5 DO

    Result := Result + 5;

===========================================

In this programming codes works in a manner that first intialize the value i to 1 and then check the condition that whether the i less than 5, i="i+1"

FOR .. DOWNTO Loop

In the case of FOR .. DOWNTO Loop the value checking is decresed format and when the value reach the condition wrong then exit loop.

Syntax of FOR .. DOWNTO Loop:

--------------------------------------------------------------

FOR Control Variable :=  Start Value DOWNTO End Value

DO Statement

--------------------------------------------------------------

The Control Variable, Start Value and End Value are same as  FOR .. TO Loop. Only difference is that in the case of  FOR .. TO Loop Control Variable is in the Increase format but in the case of  FOR .. DOWNTO Loop decrese format.

For Example:

===========================================

FOR i :=5 DOWNTO 1 DO

    Result := Result + 5;

===========================================

In this case programming code work in the manner like first assign the value 5 to i and then check the value 5>1 and then do the statements following. Next time i value decrese by 1 and then check the condition and soon.

FUNCTION PARAMETERS

FUNCTION PARAMETERS IN MICROSOFT DYNAMICS

Function parameter is one or more variables or expressions that are sent to the function through a function call. These parameters provided for function information also can able to modify that information. If there is more than one parameter, the parameters will be sepearated by commas.

There are mainly 2 types of parameter passing occur

  1. Pass By Value
  2. Pass By Reference
  • Pass By Value:- In this type of parameter passing only pass some values only. If we change thse values then it will not affect in the parent trigger or values. That is once pass the value it will not affect any kind of changes in the parent method, its only passing the value.
  • Pass By Reference:- In this kind of parameters its pass like reference of the variable, sometimes called name of the variable. Whenever we change the value of these variables it will affect the parent trigger also. Because in this type the computer knows the exact storage space of that variable or parameter. 

FUNCTIONS IN MICROSOFT DYNAMICS

FUNCTIONS IN MICROSOFT DYNAMICS

Definition

Functions are named portions of a program, some times called as Subprogram or Subroutine.

When a function is called from a set of programming code then current programming code is suspended and continued with a trigger code. And after the completion of that trigger the program control return to the origin. 

A function can be used as expression also

For example:

TotalCost := Qty * CalculatePrice

In this code CalculatePrice is one function that calculate the price and after the calculation it return some value based upon that further programming codes executes.

Built In Functions

In Microsoft Dynamics C/SIDE programming using some built in functions also. These programming codes cannot be viewed by the users and it cannot be modified.

Some of the built in functions are as follows

  • MESSAGE :- Displays a message on the screen.
  • MAXSTRLEN :- Return defined legth of string variable.
  • COPYSTR :- Returns part of a string
  • CLEAR :- Clears the passed in variable
  • ARRAYLEN :- Returns number of elements in an array.

CASE

CASE Loop or Statements

CASE Loop or statements is a conditional statement. 

Like IF loop or statement these also works in the manner that once the statement is true then some statements are executed other wise the else part will be executed. But in the case of CASE we can consolidate muliple levels of IFloops in one CASE. Some programming languages like C its called as SWITCH - CASE loop but in Navision or Microsoft Dynamics NAV we called this as CASE only.

Syntax of CASE 

-----------------------------------------------------------

        CASE Expression OF

               Value Set 1 : Statement 1;

               Value Set 2 : Statement 2;

                 ...

               Value Set n : Statement n;

             ELSE Statement n+1;

         END 

-----------------------------------------------------------

A sample program for the CASE is as follows

==============================================================

     CASE Color OF 

          Color :: Orange:

                             MESSAGE('COLOR IS ORANGE');

          Color :: Red,Color :: Green:

                             MESSAGE('COLOR IS RED OR GREEN');

            ELSE

                             MESSAGE('COLOR NOT ORANGE,RED OR GREEN');

      END

==============================================================

WITH Loop / Statement

WITH Loop / Statement

WITH Statement or loop is used to make record variables easier. 

Record variable is a complex datatype with one variable we can store multiple values like arrays. Each record having different fields and each of these fields can able to store different data types also. These fields are separated by the '.' or dot sign. If a customer record having field named Name then it can be specified like customer.Name

Syntax Of WITH Loop

Suppose we having three fields names name, address and City then it can be specified in the recod named customer as folows

     customer.Name := Txt[1];

     customer.Address := Txt[2];

     customer.City := Txt[3];

We can sort these kind of representation in the system different way so that we can minimise the number of codings that syntax of WITH Loop is as follows

----------------------------------------------------------------------------

           WITH Record Variable DO Statement

----------------------------------------------------------------------------

 By the help of this syntax we can remodify the abow code as following type of codes

=====================================================

                WITH customer DO BEGIN 

                             Name := Txt[1];

                             Address := Txt[2];

                             City := Txt[3];

                  END; 

=====================================================

Once we cross check the abow codes we found that the Record variable is not found with any of the fields. The computer will automatically konow the identification about each fields assigned to the records.

REPEAT - UNTIL Loop

REPEAT - UNTIL Loop or Statement In Microsoft Dynamics NAV C/AL

Definition

REPEAT - UNTIL Loop is a repetative loop, is used for programmes having one or more statements to be executed until some condition.

Syntax OF REPEAT - UNTIL Loop

---------------------------------------------------

REPEAT Satements UNTIL Boolean Expression

---------------------------------------------------

This works in a manner like that it will work the statements until the Boolean Expression is true. The difference Between WHILE-DO loop is that the REPEAT - UNTIL Loop will execute atleast one time and then only it will check the Boolean expression true or false. But in the case of WHILE-DO loop only execute the code when a particular condition is true.

For Example:

=======================================

REPEAT

i :=  i + 1;

Total Sales := Total Sales + Sales[i];

UNTIL Sales[i]=0;

=======================================

The abow example works in a manner like that it will execute the statement once after that check the Boolean expression Sales[i]=0 or not if the condition is true then reapeat the statement otherwise it will exit from the loop and execute the statement immediatly after that.

WHILE .. DO Loop

WHILE .. DO Loop or Statement In Microsoft Dynamics NAV C/AL

Definition

The WHILE .. DO Loop is a repetitive statement or loop, is used in the program where a certain code is to be executed as long as some condition is true.

Syntax Of WHILE .. DO Loop

-----------------------------------------------------

WHILE Boolean Expression DO Statement

-----------------------------------------------------

This is simpler than the IF loop. In the case of  WHILE .. DO Loop the system check continously the boolean expression become true then the statement between BEGIN and END execute otherwise move to next statement.

For Example:

==================================================

WHILE Sales[i+1] <> 0 DO BEGIN

     i := i + 1;

     Total Sales :=  Total Sales + Sales[i];

END;

==================================================

This is work in a manner like that check every time the Sales[i+1] <> 0 and if the condition is true then execute the statement between BEGIN and END other wise execute after the END statement.

Repetitive Statements or Loop

Repetitive Statements or Loop

Repetitive Statements or Loops are using when we want to execute one statement or more than one statement multiple times. In the case of IF loop it will work only for one time execution only. So if the user need to execute a statement more than one times based upon some condition. 

All the repetitive statements are works in a manner like that it will work repetedly until one condition satisfy and if that condition appear then it moves the control to next programming satement after the repetitive statements. And in the case of repetitive statements always having initialize variable and increment values will appear. 

Some of the Repetitive statements are

IF Statement, WHILE .. DO, REPEAT .. UNTIL etc.

Combound Statements

Combound Statements In Microsoft Dynamics NAV

Combound Statements are statements that can be used to represent multiline statements in the IF, WHILE etc like statements.

Sysntax for combound statements are

BEGIN Statement1 {; Statement2} END

For example :

=====================================

IF Quantity <> 0 THEN

     BEGIN

              UnitPrice := ExtendedPrice / Quantity;

              TotalPrice := TotalPrice + ExtendedPrice;

     END;

=====================================

Comment

Comment In Microsoft Dynamics NAV

What is a Comment?

Comment is the useful information to identify or represent a programming code.

The comment statements are not executable so we can comment the programming codes that no need to execute also.

Types Of Comments

Mainly 3 types of comments available in the Microsoft Dynamics NAV C/AL.

  1. Single Line Comment 
  2. Block Of Comment
  3. Nested Comments
  • Single Line Comments :- Single line comments are types of comments that can used to comments single line of codes. In this case, this single line comment ignore by the compiler. The Syntax used is '//'. ie, if we are placing // in any of the program codes then after that text is consider to be comment.

For Example:

================================================

//Sample code for Comment showing adding two numbers

A := B + C;

================================================

  • Block Of Comment:- Block comments are comments that allow multiline comment. Block comments start with '{' bracket and closing with '}'. ie, the text between these brackets are considered as comment portion and this cannot be repeated.

For Example:

================================================

//Sample Block comment

{

text1........

text2......

text3

}

================================================

  •  Nested Comments:- Nested Comments are types comments that represent comments in the form, a comment containing another comment. ie, the brackets of '{' is started but inside of that also another '{' rather than '}'.

For example :

================================================

//Nested Comment

{

text1........

                    {

                       text2......

                       text4..................

                      } 

text3

}

================================================

EXIT Statement

EXIT Statement In Microsoft Dynamics NAV 

EXIT statement is a type of statements that used for skip following program  trigger for avoiding errors or other purpose. Whenever an EXIT statement was there the program quit further moving the codes of that trigger and the control backs to the objects.

For exaple consider the following codes

=============================================

IF Quantity = 0  THEN

  EXIT;

Unit Price := Total Price / Quantity;

=============================================

This statement works in a manner that once the Quantity value will be '0' then the program skip the codes preceding that for avoing the division by zero error.

IF - THEN And IF - THEN - ELSE Satement In Microsoft Dynamics NAV

IF Satement In Microsoft Dynamics NAV

IF Statement is the most commonly used conditional statement that work based upon the statement is TRUE or FALSE.

Conditional Statements works like first check one condition and based upon the result of this condition further flow of the program happened. Microsoft Dynamics NAV(previously Navision) language C/AL is used other conditional statements too.

If statement or IF loop is used execute a code when a purticular statement is TRUE only and some case its used to execute some statements when the statement is FALSE too.

There are mainly 2 types of IF statement specifications

  1. IF - THEN Syntax
  2. IF - THEN - ELSE Syntax

IF - THEN Syntax : -

In this type of IF statements you have to use following type of syntax


IF boolean expression THEN  statement


This statement works in a manner that first the Boolean expression is evaluated and if the value is TRUE then the Statement excuted and if the Boolean expression is FALSE then the statements after the IF statement is executed. ie, the program skips the IF statements.

For example consider the following example:

======================================

IF Total > 50 THEN

    MESSAGE('Total Value is grater than 50');

======================================

In this sample codes we checking that if the Total is grater than 50 or not and if the value is grater than 50 we are displaying a message that Total Value is grater than 50. 

Note that the statement is indented 2 characters, this is beacuse of the better programing practice only. We can put these codes without these space also excuting the same result also we can put these statements in immediatly preceding the THEN statements. 

IF - THEN - ELSE Syntax :-

In this type of IF statements you have to use following type of syntax


IF boolean expression THEN  statement1 ELSE statement2


This time its works in the maner that if the boolean expression is true then execute the statement1 and if the condition is false then execute statement2.

For example consider the following example:

=======================================

IF Total > 50 THEN

    MESSAGE('Total Value is grater than 50')

ELSE

   MESSAGE('Total Value is Less than or Equal to 50');

=======================================

In this sample codes we checking that if the Total is grater than 50 or not and if the value is grater than 50 we are displaying a message that Total Value is grater than 50.  And if the value is less than or equal to that then display Total Value is Less than or Equal to 50.

Form Designing And Executing In Microsoft Dynamics NAV

Form Designing And Executing In Microsoft Dynamics NAV(Navision) Using C/AL

By this topic i will tell how to design a Microsoft Dynamics NAV Form  Designing and Excetions of a simple program. 

There are mainly 5 steps we have to care when we design a Simple Form without using table in the Dynamics NAV. 

  1. Designing Form
  2. Defining Variables
  3. Assigning Variables to the designed form objects
  4. Create a programe code to excute the form
  5. Run the form
  • Designing Form:- For design a form you have to first goto the Tools -> Object Designer -> Form. Then click on the New Button. Select  create a blank form and press ok. After opening that select from the menu View -> Toll Boox,  View ->Font View -> Color.                                                                                                                                                                                                                                                                                                       Tool Box is the area where containing all the tools need to be included in the form like Label, Button, Text Box.                                                                                                                                                                                                                                                                                                                  Font is the area where we can manage all the font related activites of the text. First click on the Add Label option in the Tool Box.                                                                                                                                                                                                                                                                                                              Color is the area where we can assign colors to different objects.                                                                                                                                                                 After selecting these boxes you have to  goto the Tool Box and select the Tool Frame and place them in the form, next click Add Label, then click text box notice that both the label and text boxes created at a strech. You have to place 3 text boxes in the form and one Command Button from the Tool Box. Our aim is to add the value of two items and display the value in the thrird one named Result.
  •  Defining Variables:- For doing the abow problem we have to define 3 variables named Value1,Value2 and Result. For doing this goto the View C/AL Globals section and enter the 3 variables as Decimal Data types. ie, Value1 - Decimal, Value2 - Decimal, Result- Decimal.For defining these refer http://mibutech.blogspot.com/2010/02/sample-program-to-display-stored-data.html  link.
  • Assigning Variables to the designed form objects:- For asigning values to the object is the main area where we are connecting our designed objects to the variables we are defined. For doing this we have to select each and every text box one by one and then Goto the View -> Properties option, there look the SourceExpr and then drill down the options in the right side and select one by one variables and asign. ie, click on the first text box and then asign the Value1, select second text box and asign the Sourceexpr as Value2 and in the Third one asign Result. After doing this you will see following type screen.
  • Create a programe code to excute the form:- For calulate something using the objects input data we have to define the programming code. A sample program for calculate the addition of Value1 and Value2 and display the value in the Result is as follows.  -----------------------------------------------------------------------------------------           Result := Value1 + Value2;                                                                                                          -----------------------------------------------------------------------------------------    You have to place this in the Form OnRun(). For doing this click design buttor in the Object desginer-> Form. Goto the OnRun() and type folowing code there.     
  •   Run the form:- For run the form you have to open the Object designer then press the Run Button. Then the following picture like result you will get. 

Logical and Relational Operators & Expressions

Logical and Relational Operators In The Microsoft Dynamics NAV C/AL

Logical and Relational operators are always result in a boolean value ie, either TRUE or FALSE.

Relational Operator

Relational operator is used in the relational expressions to test a relationship between the term preceding it and the term following it, resulting in a boolean value.

These operators are listed below

  • = (equal to)
  • IN (Included in set)
  • < (less than)
  • > (grater than)
  • <= (less than or equal to)
  • <> (not equal to)

Logical Operator

Logical operator uses one or two Boolean terms in a logical expression. The logical binary operators are AND, OR and XOR (exclusive or). The one logical unary operator is NOT.

Related Posts with Thumbnails