25
ASSIGNMENT STATEMENTS AND EXPRESSIONS Dynamics NAV 2013 Shan Abeywicrema | Jinasena Infotech | www.jinasenainfotech.com

ASSIGNMENT STATEMENTS AND

Embed Size (px)

Citation preview

Page 1: ASSIGNMENT STATEMENTS AND

ASSIGNMENT STATEMENTS AND

EXPRESSIONS

Dynamics NAV 2013

Shan Abeywicrema | Jinasena Infotech | www.jinasenainfotech.com

Page 2: ASSIGNMENT STATEMENTS AND

Assignment statements assign a value to a variable. This means that a variable can represent different values at different times.

Assignment Statements

Page 3: ASSIGNMENT STATEMENTS AND

Assignment means to set a variable to a value.

When a variable has a value, it keeps that value until another value is assigned to it, or until the current set of code ends and the system no longer keeps track of the variable

Assignment

Page 4: ASSIGNMENT STATEMENTS AND

A statement in programming context is a single complete programming instruction that is written as code

Statement

Page 5: ASSIGNMENT STATEMENTS AND

Certain function calls, such as the MESSAGE function, can be a statement on their own. They are known as function call statements

[return value :=] <Function Call>

Example:: MESSAGE function

Function Call Statement

Page 6: ASSIGNMENT STATEMENTS AND

The syntax of an assignment statement is almost as easy as the syntax of the function call statement. The syntax is as follows

<variable> := <expression>

Example :: Integer Number:=10;

Assignment Statement

Page 7: ASSIGNMENT STATEMENTS AND

The “colon equals” (:=) is known as the assignment operator. You use it to assign a value or an expression that evaluates to a value to a variable.

:=

Assignment Operator

Page 8: ASSIGNMENT STATEMENTS AND

A single programming statement may span several code lines; one code line may consist of multiple statements.

Therefore, the C/AL compiler must be able to detect when one statement ends and another statement begins.

[ <statement> { ; <statement> } ] Example Integer Num:=10;

The Statement Separator

Page 9: ASSIGNMENT STATEMENTS AND

Before you can assign a variable to a value, the type of the value must match the type of the variable. However, within limits, you can automatically convert certain types in an assignment operation.

Automatic Type Conversions

Page 10: ASSIGNMENT STATEMENTS AND

You can convert variables of string data types (code and text) automatically from one to the other. For example, if Description is a variable of type Text, and CodeNumber is a variable of type Code, the following statement is valid:

CodeNumber := Description Automatic conversion does have limitations. For example, if the value of the Description text

variable has more characters than the length of the CodeNumber variable, an error occurs when the program runs and executes this statement. This type of error is known as a run-time error.

String Data Types

Page 11: ASSIGNMENT STATEMENTS AND

Variables of the numeric data types (integer, decimal, option, and char) can convert automatically from one to another

Numeric Data Types

Page 12: ASSIGNMENT STATEMENTS AND

Demonstration: Create a Simple Assignment Statement

Use Assignment Statements and the Symbol Menu

Page 13: ASSIGNMENT STATEMENTS AND
Page 14: ASSIGNMENT STATEMENTS AND
Page 15: ASSIGNMENT STATEMENTS AND
Page 16: ASSIGNMENT STATEMENTS AND
Page 17: ASSIGNMENT STATEMENTS AND
Page 18: ASSIGNMENT STATEMENTS AND
Page 19: ASSIGNMENT STATEMENTS AND
Page 20: ASSIGNMENT STATEMENTS AND
Page 21: ASSIGNMENT STATEMENTS AND
Page 22: ASSIGNMENT STATEMENTS AND

Demonstration: Set Option Constants

Page 23: ASSIGNMENT STATEMENTS AND

Demonstration: Compile-Time and Run-Time Errors

Page 24: ASSIGNMENT STATEMENTS AND

Expression An expression specifies the information to

generate a desired value. Similar to a variable and a constant, an expression has a type and a value. expression is evaluated at run time to determine its value.

Quantity * UnitCost

Expressions, Terms, and Operators

Page 25: ASSIGNMENT STATEMENTS AND