Presentation is loading. Please wait.

Presentation is loading. Please wait.

Egyptian Language School Computer Department

Similar presentations


Presentation on theme: "Egyptian Language School Computer Department"— Presentation transcript:

1 Egyptian Language School Computer Department
Third Prep. 2nd Term Chapter 1

2 The program user can enter values with different types:
Name, Address, Level  Text (letters+ number + symbols) Age ,Total Grades  Numeric (Whole number or fraction number) Gender  Boolean (True / False) Birth date  Date (date / time) Favorite Color  Color

3 Why we have to learn the different data types?
Each data type has a way in which are stored in computer memory(RAM): This is mainly for using the computer memory optimally, In terms of storage space and arithmetic and logical operations that take place on these values Each Data Type has : Storage Space in the memory Range of values (the values that can be represented by this type)

4 Data Types 1- Numerical 3- Miscellaneous Data Types
2- Character Data Type A- Integral String Char Object Date Boolean Byte Short Integer Long range 0255 Storage space 4bytes B- Non-integral Single Double Decimal

5 It`s clear that properties are data storage location and their values have a specific data type For Example: The property Text  String The property AutoSize Boolean The property Width Integer VB.Net Supports types other than the standard Data types like Font , Color , ………..etc The property BackColor Color

6 Variables Are reserved memory locations to store values temporarily which have: Names Data Types Note: These Values can be changed during program execution

7 Variable Declaration Dim VariableName As DataType Example :
Dim V_ Name As String Dim Age As Byte Dim Area As single Dim Gender As Boolean Dim B_Date As Date Dim Level As Char

8 Naming Variables √ Consists of letters, numbers & Underscores(_)
√ Must begin with a letter or underscore(_) √ It’s preferable that variable names reflect s its contents. × Shouldn't contain symbols, special characters ( * ,?, !, .) × Don’t use reserved words such as (Dim, Single , As)

9 Test your self State whether the variable name is valid or not according to the naming rules Variable name Validation Dim 1A as single Dim Stud name As string Dim Class-name As string Dim Stud_grade As Double Dim Date As Integer Dim R As Double Not Valid Not Valid Not Valid Valid Not Valid Valid

10 Constants They are reserved memory places that have a data type.
Declaring constants means to assign values to them , these values can’t change during program execution.

11 Declaration Rule Const Pi As single = 22/7
Const Constant name As Data Type (= Value) Const Pi As single = 22/7 Const BirthDate As Date = #1/24/2002# Const Country As String = “ Egypt”

12 Comparison between Variables and Constants
They are reserved places in computer memory(RAM) declared and determined by their names and data types. Their values can be changed during the running of the program . They take fixed value and can`t change during the progress of the program . Declaration in VB.Net is done by the key word or the command ( DIM ) And the declaration statement is: DIM Variable as Data = [initial value] Name Type Declaration in VB.Net is done by the key word or the command ( Const ) Const Constant as Data = Value Name Type Assigning initial value to variables during declaration is optional. Assigning value to constants during declaration is a must. Such as : price of product - value of the tax – address – Birthrate of student - Gender – no. of books in the library. etc…. Such as : mathematical constants like (Ԓ) – Some physics constants like gravity acceleration , the speed of light and speed of sound.etc….

13 Scope of Variables Variables & constants can’t be used except in the scope of their declaration. We can declare variables & constants on a class level & then we don’t the declaration process at each scope of the Event procedure.

14 The assignment statement
Left side Assignment Operator Right side Variable Or Property = Abstract value or Value from the variables or Property or Value from an Expression

15 Assignment Examples The Right side of the Equation could be
Dim Number1, Number2 AS Integer Dim Salary As single = Abstract value Number1=5 Value from a variable Number2=Number1 Value from a property Name=TextBox1.Text Value from Expression Salary= Salary /3

16 We use the variables through an assignment statement after declaration
Using Variables We use the variables through an assignment statement after declaration If the variable is on the right side of the assignment statement, this indicates that values stored in variables . Dim U_Name As String U_ Name = Textbox1 . Text If the variable is on the right side of the assignment statement, this means that it reflects (outputs) its value. Dim U_Name As String= “ Mai” Textbox2 . Text = U_ Name

17 The Idea of the program In this program we will make assignments of inputs received from the user to their corresponding variables then reflects their values in control (Label5)

18 The idea of the Program In this program we will make assignments of inputs received from the user to their corresponding variables then reflects their values in the control (label5)

19 Me.Label5.Text = u_name & vbCrLf & u_D_B & vbCrLf & _ u_gender & vbCrLf & u_C_F
Keyword function Me Express the current form (the control is on the same form where we write the codes) & Concatenation ( to append or join text of the codes together) vbCrLf Values of Variables are separated from each other by new line. (_) or underscore Enables writing lines of code in more than one line (to organize and simplify the process of reading codes) Rem or Appostrophe ( ‘ ) To indicates the line of code as comment (what`s written after is neglected and isn`t considered by the compiler while program execution )

20 Priority Rules for Arithmetic Operations (Operator Precedence)
( ) (from inside to out) ^ (exponent/ raise to the power) * / (from left to right) (from left to right) Solve: A= (2*(3^2)/ 3-1).

21 There are 3 types of errors
Syntax Errors Logical Errors Runtime Error There are 3 types of errors

22 Din X As Byte - Dim Area As Sengl
Syntax Errors this type of error is easy to detect because the IDE helps and displays the syntax of any command as we type it Refers to the spelling mistakes in writing the reserved words or error in the common syntax commands of the language. Din X As Byte - Dim Area As Sengl Din instead of Dim and Sengl instead of single Const PI As single No value assigned to constant PI during the declaration.

23 Logical Errors this type of error happens when we get incorrect results after executing the program
Due to the wrong formulating in arithmetic or logic expressions Area = Pi + Radius ^ 2 On running the program , It will give wrong result because we used sign (+) instead of (*) To overcome this type of error, review the written code, and test the program with data already validated to check .

24 Runtime Errors this type of error is discovered when the program is running
Due to assigning value lesser or greater than the range of the data type declared or not compatible with the data type of the variable. Dim Age As Byte Age = or Age = - 10 it shows Overflow which means out of range Age =“ five” it assigns string value instead of numeric value as declared


Download ppt "Egyptian Language School Computer Department"

Similar presentations


Ads by Google