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

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

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.
Data types and variables
IS437: Fall 2004 Instructor: Dr. Boris Jukic Data Types, Constants, Variables, Scope, Conversion.
Chapter 2 Data Types, Declarations, and Displays
Basic Elements of C++ Chapter 2.
Apply Sub Procedures/Methods and User Defined Functions
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.
CS0004: Introduction to Programming Variables – Numbers.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
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.
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.
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.
PSU CS 106 Computing Fundamentals II VB Declarations HM 5/4/2008.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
CSCI 3327 Visual Basic Chapter 6: More Examples of Methods UTPA – Fall 2011.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Visual Basic Programming I 56:150 Information System Design.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
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.
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.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
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.
Data Types. Visual Basic provides data type Single for storing single-precision floating-point numbers. Data type Double requires more memory to store.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
A variable is a name for a value stored in memory.
VB Script V B S.
Chapter Topics The Basics of a C++ Program Data Types
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
Basic Elements of C++.
Object Oriented Programming
2. Understanding VB Variables
Object-Oriented Programming: Classes and Objects
Basic Elements of C++ Chapter 2.
Chapter 2.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
C++ Data Types Data Type
CS285 Introduction - Visual Basic
Tonga Institute of Higher Education
Methods.
C++ Programming Basics
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 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, bytesDateTime Date 0 through (unsigned)2 bytesChar Char (single character) 0 through 255 (unsigned)1 byteByte True or FalseDepends on implementing platformBoolean Value rangeNominal storage allocationCommon language runtime type structureVisual Basic type

Data Types -2,147,483,648 through 2,147,483,647 (signed)4 bytesInt32Integer E-324 through E+308 † for positive values E+308 through E-324 † for negative values;8 bytesDoubleDouble (double-precision floating-point) smallest nonzero number is +/ (+/-1E-28) † 0 through +/-79,228,162,514,264,337,593,543,950,335 (+/ E+28) † with no decimal point; 0 through +/ with 28 places to the right of the decimal;16 bytesDecimal

Data Types E-45 through E+38 † for positive values E+38 through E-45 † for negative values;4 bytesSingleSingle (single-precision floating-point) -32,768 through 32,767 (signed)2 bytesInt16Short (short integer) -128 through 127 (signed)1 byteSByte 8 bytes on 64-bit platform Any type can be stored in a variable of type Object4 bytes on 32-bit platformObject (class)Object -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18 † ) (signed)8 bytesInt64Long (long integer)

Data Types 0 through 65,535 (unsigned)2 bytesUInt16UShort Each member of the structure has a range determined by its data type and independent of the ranges of the other membersDepends on implementing platform(inherits from ValueType)User-Defined (structure) 0 through 18,446,744,073,709,551,615 (1.8...E+19 † ) (unsigned)8 bytesUInt64ULong 0 through 4,294,967,295 (unsigned)4 bytesUInt32UInteger 0 to approximately 2 billion Unicode charactersDepends on implementing platformString (class)String (variable-length) † 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