Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.

Slides:



Advertisements
Similar presentations
Integrated Business Applications with Databases (D3) Jenny Pedler
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
Data types and variables
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
CS150 Introduction to Computer Science 1
Chapter 2 Data Types, Declarations, and Displays
VB .NET Programming Fundamentals
Basic Elements of C++ Chapter 2.
BACS 287 Programming Fundamentals 1. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Variables State Scope Lifetime.
Objectives You should be able to describe: Data Types
.NET Data types. Introduction ٭ A "data type" is a class that is primarily used just to hold data. ٭ This is different from most other classes since they're.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Language Elements 1. Data Types 2 Floating Point (real) Single Precision Double Precision Decimal Fixed Point (integer) Byte Short Integer Long Numerical.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 2: Using Data.
Lecture #5 Introduction to C++
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Applications Development
Items in Visual Basic programs
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Copyright © – Curt Hill Types What they do.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming with Microsoft Visual Basic th Edition
CSI 3125, Preliminaries, page 1 Data Type, Variables.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.
1 Writing Software Kashef Mughal. 2 Algorithms  The term algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem.  An Algorithm.
1.2 Primitive Data Types and Variables
Murach, Chapter 4. Two Data Types Value Types – Store their own data Reference Types Do not store their own data Stores a reference to an area of memory.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
Data Type Summary (Visual Basic) Visual Basic typeCommon language runtime type structure Nominal storage allocation Value range Boolean Depends on implementing.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
A variable is a name for a value stored in memory.
Object-Oriented Programming: Classes and Objects
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Data Types, Arithmetic Operations
2. Understanding VB Variables
Object-Oriented Programming: Classes and Objects
Chapter 2.
CIS16 Application Development Programming with Visual Basic
C++ Data Types Data Type
Tonga Institute of Higher Education
Variables and Constants
Presentation transcript:

Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007

Goal Variables and its types Scope, lifetime and access level of variables Constant Expression Statement Procedure Sub Procedure Functions

Variable It is the name of memory location where we put our data. Declaring variable Use Dim keyword Assigning values (sometimes declared with default value assigned) Using variable For data manipulation / mathematical calculation

Variables Dim x as integer = 2 Dim L as double = 10 Dim p as double = 5 Dim R1 as double, R2 as double Sub calcReac() R2 = P*x / L R1 = P – R2 End sub

Data Types Visual Basic type Common language runtime type structure Nominal storage allocation Value range Boolean Depends on implementing platform True or False Byte 1 byte0 through 255 (unsigned) Char (single character) Char2 bytes0 through (unsigned) Date DateTime8 bytes0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999

Data Types Decimal 16 bytes0 through +/- 79,228,162,514,264,337,593,543,950,33 5 (+/ E+28) † with no decimal point; 0 through +/ with 28 places to the right of the decimal; smallest nonzero number is +/ (+/- 1E-28) † Double (double- precision floating- point) Double8 bytes E+308 through E-324 † for negative values; E-324 through E+308 † for positive values IntegerInt324 bytes-2,147,483,648 through 2,147,483,647 (signed)

Data Types Long (long integer) Int648 bytes-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18 † ) (signed) ObjectObject (class) 4 bytes on 32-bit platform Any type can be stored in a variable of type Object 8 bytes on 64-bit platform SByte 1 byte-128 through 127 (signed) Short (short integer) Int162 bytes-32,768 through 32,767 (signed) Single (single- precision floating- point) Single4 bytes E+38 through E-45 † for negative values; E-45 through E+38 † for positive values

Data Types String (variable- length) String (class)Depends on implementing platform 0 to approximately 2 billion Unicode characters UIntegerUInt324 bytes0 through 4,294,967,295 (unsigned) ULongUInt648 bytes0 through 18,446,744,073,709,551,615 (1.8...E+19 † ) (unsigned) User-Defined (structure) (inherits from ValueType) Depends on implementing platform Each member of the structure has a range determined by its data type and independent of the ranges of the other members UShortUInt162 bytes0 through 65,535 (unsigned) † In scientific notation, "E" refers to a power of 10. So 3.56E+2 signifies 3.56 x 102 or 356, and 3.56E-2 signifies 3.56 / 102 or

Data Types Integers are used for whole numbers Single is used for floating point number Double is used for floating point number with greater accuracy w.r.t. Single Long is used for financial calculation String and char is used for Text variable Object is used for reference of classes / controls Date / time is clear from its name

Notes for Variables VB.Net variables are not case sensitive Conversion of variable from one form to other can be implicit or explicit Example of implicit conversion: Dim intA as integer = 0 Dim doubA as double = 2.17 intA = doubA Example of explicit conversion: Dim intA as integer = 0 Dim doubA as double = 2.17 intA = integer.parse(doubA)

Data Conversion Use: Integer.parse Double.parse Cdbl Cint Val Variable.tostring

Example of object / control variable Dim mybtn as button Assignning a button to a form control btn1 = New Button btn1.Top = 38 btn1.Left = 12 btn1.Size = New Size(45, 33) btn1.Text = “Test btn” AddHandler btn1.Click, AddressOf btn1 _Click Me.Controls.Add(btn1)

Example of object / control variable Event handler code: Private Sub mybtn_Click(ByVal sender As Object, ByVal e As EventArgs) ‘Write some code End Sub

Scope of variable (Assign) Normally, a variable is in scope, or visible for reference, throughout the region in which you declare it. In some cases, the variable's access level can influence its scope.

Scope of variable To make a variable visible only within a block 1.Place the Dim Statement (Visual Basic) for the variable between the initiating and terminating declaration statements of that block, for example between the For and Next statements of a For loop.Dim Statement (Visual Basic) 2.You can refer to the variable only from within the block. To make a variable visible only within a procedure 1.Place the Dim statement for the variable inside the procedure but outside any block (such as a With...End With block). 2.You can refer to the variable only from within the procedure, including inside any block contained in the procedure. Scope at Module or Namespace Level 1.For convenience, the single term module level applies equally to modules, classes, and structures. The access level of a module level variable determines its scope. The namespace that contains the module, class, or structure also influences the scope.

Scope of variable To make a variable visible throughout a module, class, or structure 1.Place the Dim statement for the variable inside the module, class, or structure, but outside any procedure. 2.Include the Private (Visual Basic) keyword in the Dim statement.Private (Visual Basic) 3.You can refer to the variable from anywhere within the module, class, or structure, but not from outside it. To make a variable visible throughout a namespace 1.Place the Dim statement for the variable inside the module, class, or structure, but outside any procedure. 2.Include the Friend (Visual Basic) or Public (Visual Basic) keyword in the Dim statement.Friend (Visual Basic)Public (Visual Basic) 3.You can refer to the variable from anywhere within the namespace containing the module, class, or structure.

Life time of variables (Assign) The lifetime of a declared element is the period of time during which it is available for use. Variables are the only elements that have lifetime. For this purpose, the compiler treats procedure parameters and function returns as special cases of variables. The lifetime of a variable represents the period of time during which it can hold a value. Its value can change over its lifetime, but it always holds some value.

Scope of variable (Assign) Different life times Beginning End Extension

Access Level (Assign) The access level of a declared element is the extent of the ability to access it, that is, what code has permission to read it or write to it. This is determined not only by how you declare the element itself, but also by the access level of the element's container. Dim, Private, Protected, Friend, Protected Friend or Public.

Constant Constant is the name of memory location with fixed value. Public Const E As double = 200E9 Private Const E As Double = 200E9 Protected Friend Const E As String = 200E9

Expression Constants and variables combined with algebraic / logical operator is called expression Can be algebraic or logical If x > 3 then Do something End if If 3*x = 4 then Do something End if

Statement A single line of code which is compiled successfully is called statement Statements are packed in to procedures

Procedures Procedure is a group statements or block of code Sub Procedure Function

Sub Procedure Sub-Procedure is a block of code which do operation and do not report any result or Any code within sub / end sub is called sub procedure Sub are within block of sub / end sub Statements within sub / end sub should be limited to a dozen line of code Sub may or may not accept arguments

Function Function is a procedure which do required operation and reports the result as well Code within Function / End Function is called a functions Function always need arguments These are also called mini-programs

Q & A

Define: Variable Constant Expression Statement Scope of variable Procedure Sub Procedure Function

Thanks