Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.

Slides:



Advertisements
Similar presentations
Tutorial 31 Variable Memory location whose value can change as the program is running. Used to hold temporary information Used to control the type of data.
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 3: Using Variables and Constants
Variables / Scope. Variable Memory location whose value can change as the program is running. Used to hold temporary information Used to control the type.
1.
String Variables Visual Basic for Applications 4.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Data Types and Operations Programming Fundamentals (Writing Code)Programming Fundamentals (Writing Code)
1 Pertemuan 03 Representing Data Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Chapter 2: Introduction to C++.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Variables and Constants
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Object Variables Visual Basic for Applications 3.
CHAPTER THREE Representing Data: Constants and Variables.
2440: 211 Interactive Web Programming Expressions & Operators.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Chapter 3 Part 11 Variables, Constants, and Calculations Chapter 3 Section 3.3 Chapter 3 Section 3.4.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
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.
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.
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.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 7 Where Can I Store This?
Programming with Microsoft Visual Basic th Edition
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
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.
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.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
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.
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.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
© 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.
Introduction to Computer CC111 Week 09 Visual Basic 2 Visual Basic Variables 1.
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
Fundamentals 2.
A variable is a name for a value stored in memory.
Visual Basic Variables
Chapter 3: Using Variables and Constants
2. Understanding VB Variables
Microsoft Visual Basic 2005 BASICS
2.1 Parts of a C++ Program.
Numbers.
CIS16 Application Development and Programming using Visual Basic.net
CIS16 Application Development Programming with Visual Basic
Chapter 2: Java Fundamentals
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Introduction to C++.
An Introduction to Programming with C++ Fifth Edition
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Programming Fundamental-1
Presentation transcript:

Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants

Tutorial 3: Using Variables and Constants2 Creating Variables and Named Constants Lesson A Objectives After completing this lesson, you will be able to:  Create a local and form-level variable  Select an appropriate data type for a variable  Select an appropriate name for a variable  Assign data to an existing variable  Create a named constant

Tutorial 3: Using Variables and Constants3 Using Variables to Store Information  The memory locations are called variables, because the contents of the locations can change as the program is running  You should assign a descriptive name to each variable used in an application – it should help you remember the variable’s data type and purpose

Tutorial 3: Using Variables and Constants4 Selecting a Data Type for a Variable TypeSizeTypeSize Byte1Short2 Char2Integer4 Boolean4Long8 Decimal12Single4 Double8StringVaries Date8ObjectAnything

Tutorial 3: Using Variables and Constants5 Choose the Correct Data Type Short, Integer, LongUsed to store whole numbers Single, DoubleStore floating-point numbers DecimalStores numbers with a decimal point BooleanStores True and False CharStores one Unicode character ByteStores 8-bits of data DateStores date and time information StringStores a sequence of characters

Tutorial 3: Using Variables and Constants6 Selecting a Name for a Variable  Figure 3-4 lists the three characters typically associated with the Visual Basic.NET data types  It is a common practice to type the letter m and the three-character ID using lowercase letters, and then use Pascal-case for the remainder of the variable’s name

Tutorial 3: Using Variables and Constants7

8

9 Rules for Naming Variables  Name must begin with a letter  Name can contain only letters, numbers, and the underscore. No punctuation characters or spaces are allowed  Name cannot exceed 255 characters  Name cannot be a reserved word

Tutorial 3: Using Variables and Constants10 Declaring a Variable Accessor variablename As Datatype [ = InitialValue] Accessor is [Public|Private|Static|Dim] Dim intTotal As Integer Dim sngRadius As Single = 12 Dim intYellow, intBlue As Integer Public strName As String = “Diane Zak”

Tutorial 3: Using Variables and Constants11 Assigning Data to an Existing Variable  Quotation marks differentiate a string from both a number and a variable name  The Dim statement creates the intNumber variable in memory and automatically initializes it to the number 0

Tutorial 3: Using Variables and Constants12 Assigning Data to a Variable  The intNumber = 500 assignment statement removes the zero from the intNumber variable and stores the number 500 there instead  The intNumber = intNumber *2 assignment statement first multiplies the contents of the intNumber variable (500) by the number 2, giving 1000 The assignment statement is of the form variablename = value sngHours = 38.5 sngBonus = sngSales * 0.1 strName = “Mary” intNumber = 500

Tutorial 3: Using Variables and Constants13 The Scope of a Variable  A variable’s scope indicates which procedures in an application can use the variable – either Dim, Public or Private statement is entered  When you declare a variable in a procedure, the variable is called a local variable and is said to have procedure scope, because only that procedure can use the variable  When you declare a variable in the form’s Declarations section, the variable is called a form- level variable and is said to have module scope

Tutorial 3: Using Variables and Constants14 Creating a Local Variable  Created with the Dim statement  The Dim statement is entered in an object’s event procedure  Only the procedure in which it is declared can use the variable  Removed from memory when the procedure ends

Tutorial 3: Using Variables and Constants15 Creating a Form-level Variable  Created with the Public/Private statement  Entered in a form’s General declarations section  Can be used by any of the procedures in the form  Removed from memory when the application ends or the form is destroyed

Tutorial 3: Using Variables and Constants16 Constants  Literal constant  an item of data whose value cannot change while the program is running  Examples:  7  “Mary”  Named constant  a memory location whose contents cannot be changed while the program is running  Examples:  conPi  conRate

Tutorial 3: Using Variables and Constants17 Creating a Named Constant  A memory location whose value cannot change during run time  Syntax: [Public|Private] Const constname [As datatype] = expression  Examples:  Const conPi As Single =  Public Const conMaxAge as Integer = 65