Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Slide 1 Chapter 4 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5; a literal (5) is.
1.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 2: Introduction to C++.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
Variables and Constants
CS0004: Introduction to Programming Variables – Numbers.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Chapter 4 Variables and Constants. Goals and Objectives 1. Understand simple data types (int, boolean, double). 2. Declare and initialize variables using.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Chapter 2: Using Data.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamentals of GUI Programming. Objectives: At the end of the session, you should be able to: describe the guidelines that are used for creating user-friendly.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Chapter 2 Variables.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Chapter 6 Looping Structures. Do…LoopDo…Loop Statement Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 –The Loop While operates.
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
© 2005 Lawrenceville Press Slide 1 Chapter 4 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms:
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.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Making Interactive Programs with Visual Basic .NET
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
© 2006 Lawrenceville Press Slide 1 Chapter 4 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
Microsoft Visual Basic 2010 CHAPTER FOUR Variables and Arithmetic Operations.
Bill Tucker Austin Community College COSC 1315
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
Chapter 4 Assignment Statement
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
Visual Basic Variables
Variables and Arithmetic Operations
Chapter 3 Assignment Statement
Variables and Arithmetic Operations
Microsoft Visual Basic 2005 BASICS
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
CHAPTER FOUR VARIABLES AND CONSTANTS
Primitive Types and Expressions
Chapter 2 Primitive Data Types and Operations
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Presentation transcript:

Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with meaningful names. It makes code easier to read, understand and modify  Variables are created using a declaration statement. Dim variableName As Type Ex: Dim length As Integer Data Type: determines the type of data the variable will store

Slide 2 Chapter 3 Variables   A variable (aka: Identifier) – must begin with a lowercase letter and contain only letters, numbers, and special characters. Any word after the first must be uppercase. NO SPACES  Ex: rectangleLength   Multiple variables with the same data type can be declared in a single statement  Ex: Dim length, width As Integer

Slide 3 Chapter 3 Variable Assignment Applications use many variables: Dim side As Integer = 5‘side of square Dim area As Integer‘calculated area of square area = side * side‘ value of area now 25 A variable can store only one value at any time. Dim side As Integer; side = 5; side = 10; side 5 10

Slide 4 Complete Review: Square Area – part 1 of 3 Pg 66

Slide 5 Chapter 3 Retrieving User Input  Input can be in the form of data typed by the user at run time. (The user can enter values in the textbox when the app. is running)  A TextBox object allows users to enter values.  A label is often placed near a text box to tell the user what kind of input is expected. This is called a prompt.

Slide 6 Chapter 3 The TextBox Control  (Name) should begin with txt.  Text is what is displayed in the text box. At run time, this property can be used in an assignment statement to retrieve the data typed by the user.  TextAlign sets the alignment of text relative to the text box.  MaxLength can be set to a numeric value indicating the maximum number of characters allowed in the text box.  CharacterCasing: Normal, Upper, or Lower.

Slide 7 Chapter 3 The Val() Function  A function performs a single, well-defined task and returns a value.  Val() is used to convert text box data to a numeric value. It takes the form: variableName = Val(Me.textbox.Text) A TextChanged event procedure is sometimes coded for a TextBox object.

Slide 8 Complete Review: Square Area – Part 2 of 3 Pg Complete Review: Rectangle Area Pg 69

Slide 9 Chapter 3 Built-In Data Types TypeUsed For Integer whole numbers Double numbers with a decimal portion Decimal currency values Date dates Char individual characters String a set of characters Boolean true/false, on/off, yes/no values

Slide 10 Chapter 3 Type Conversion In an assignment statement, Visual Basic automatically converts data to match the type of the variable it is being assigned to. For example: Dim x As Integer x = 6.7'x assigned 7

Slide 11 Complete Review: Total Distance Pg 71

Slide 12 Chapter 3 Variable Scope The placement of a variable declaration is important because it determines the variable's scope. The scope of a variable is the set of statements that can access the variable. A global variable is accessible to any code in the form class. A local variable is accessible to the procedure it is declared in only.

Slide 13 Complete Review: Scope Demo Pg 72-73

Slide 14 Chapter 3 Integer Division Integer division ( \ ) truncates the decimal portion of the quotient. Only the integer portion of the quotient is returned: Dim intX As Integer intX = 20 \ 7 intX is assigned to 2 because the whole number portion of the quotient is 2.

Slide 15 Chapter 3 Modulus Division Modulus division returns the remainder of a division operation: Dim intX As Integer intX = 20 Mod 7 intX is assigned to 6 because the remainder of 20 \7 is 6 Modulus division is used to separate digits of a number. Ex: finding the minutes left over after hours have been accounted for

Slide 16 Complete Review: Skyhook International Pg 74

Slide 17 Chapter 3 Named Constants  A constant is a name for a memory location that stores a value that cannot be changed from its initial assignment.  Declaring a constant takes the form: Const variable name As Data Type Example: Const MATH_PI As Double = 3.14  Constant identifiers are typically all uppercase with an underscore ( _ ) separating words within the identifier name.  Constants declarations are usually global since they do not change. Constants are declared before variables.

Slide 18 Chapter 3 Visual Basic Keywords – Keywords have special meaning to VB compiler, therefore they cannot be used as variable or constant names AndDimFalseLongReturn BooleanDoFinallyMeSelect ByteDoubleForModShort CallEachFriendModuleSingle CaseElseFunctionNewStatic CatchElseIfGetNotStop ConstEndHandlesNothingString DateEnumIfObjectStructure DecimalEraseInOrSub DeclareErrorIntegerPrivateThen DefaultEventIsProtectedTo DelegateExitLikePublicTrue

Slide 19 Complete Review: Circle Area part 1 of 2 Pg 75

Slide 20 Chapter 3 Programming Errors  Syntax errors violate the rules of Visual Basic.  Logic errors, also called semantic errors, occur in statements that are syntactically correct, but produce undesired or unexpected results.  Run-time errors, also called exceptions, halt program execution at the statement that cannot be executed.

Slide 21 Chapter 3 The Visual Basic Debugger The screen shows break mode where program execution has stopped at a breakpoint. The Watch (at the bottom of the screen) shows the current value of selected variables. Selecting Debug -> Step Into steps through the program statement by statement.

Slide 22 Chapter 3 Code Conventions  Variable identifiers should begin with a lowercase letter and any word after the first within the identifier should begin with an uppercase letter.  Group variables together in the same declarations only when variables represent related items.  Use a blank line after a group of declarations to make it clear where declarations end.  Use a descriptive prompt next to a text box to tell the user what kind of input is expected.

Slide 23 Chapter 3 Code Conventions (cont.)  Choose data types that appropriate for the type of data being represented.  Declare variables so that their scope is limited to where they are needed.  Constant identifiers should be all uppercase with underscore characters separating words.  Group constant declarations before variable declarations.

Slide 24 Complete Review: Square Area – Part 3 of 3 pg 77