Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.

Slides:



Advertisements
Similar presentations
Ch. 3 Variables VB.Net Programming. Data Types Boolean – True or False values Short – Small integers (+/- 32,767) Integer – Medium-size integers (+/-
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 3: Using Variables and Constants
Chapter 3: Using Variables and Constants Programming with Microsoft Visual Basic 2005, Third Edition.
Lecture Set 4 Data Types and Variables Part B – Variables, Constants, Expressions Conversion Rules Options Strict, Option Explicit Scope of Definition.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
1.
Chapter 3 Variables, Constants, and Calculations
CVEV 118/698 Visual Basic Lecture 1 Prof. Mounir Mabsout Expert 1: Elsa Sulukdjian Expert 2: Walid El Asmar.
Slide 1 Variables, Constants and Data Types. Slide 2 Variables v Three components define a variable: –Name (memory location) –Type –Information (value)
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
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:
Lec2 P 1 CP2030 Visual Basic For C++ Programmers Copyright © University of Wolverhampton CP2030 VBFC Lecture 2 Back to Index v Basic Data Types v Arithmetic.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 3 Variables, Constants,
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Chapter Three Using Variables and Constants Programming with Microsoft Visual Basic th Edition.
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Variables & Math Operators CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Chapter 3: Using Variables and Constants
Programming with Microsoft Visual Basic th Edition CHAPTER THREE USING VARIABLES AND CONSTANTS.
3-1 Chapter 3 Variables, Assignment Statements, and Arithmetic.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
CHAPTER THREE Representing Data: Constants and Variables.
Microsoft Access Using Visual Basic Routines. Visual Basic Datatypes Boolean Byte Currency Date Double Integer Long Object Single String Variant Hyperlink.
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.
Variables, Constants, and Calculations
Lecture 8 Visual Basic (2).
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Access VBA Programming for Beginners - Class 2 - by Patrick Lasu
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 3 P. 1 Data - Variables and Constants Definition A variable is a value which can change during program execution. A constant is a value which can.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Variable, Constants and Calculations Dr Mohammad Nabil Almunawar.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Three Using Variables and Constants.
# 1# 1 What is a variable that you create? What is a constant that you create? What is an intrinsic (built-in) constant? What variables are built in?
Programming with Microsoft Visual Basic th Edition
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
CHAPTER THREE Representing Data: Constants and Variables.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
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.
Representing Data: Constants and Variables
A variable is a name for a value stored in memory.
An Application Uses Variables to Hold Information So It May Be Manipulated, Used to Manipulate Other Information, or Remembered for Later Use.
2. Understanding VB Variables
Lecture Set 4 Data Types and Variables
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
VB Variables and Data
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Presentation transcript:

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Ch. 3:Variables, Constants, & Calculations  Data—Variables, Constants, & Controls  Data Types  Naming Conventions  Variable Scope  Calculations  Val function  Arithmetic Operations  Formatting Data  Programming Hints—Counting/Summing

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Data—Variables & Constants Data Types –Boolean, Byte, Currency –Date, Double, Integer, Long –Single, String, Variant intMaximumNumber = 100 intMaximumNumber 100

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Declaring Variables & Constants  Variables: Dim variable-name As data-type  Constants: Const constant-name As data-type = value  Most important: Force varibles to be explicitly declared: Select Tools, Options, Editor tab, and click the “Require Variable Declaration” check box.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Naming Variables & Constants  Naming rules keep track of variable types  Naming rules help you remember which are constants and which are not  They avoid data conversion  Default data type is Variant  You can detect misspellings by typing variables in lowercase

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Naming Variables  All lowercase variables are converted to their “dimmed” spelling.  Attach prefix to the variable name: bln-Boolean, cur-currency, int-integer, sng-single precision, str-string  Examples: strSocialSecNum, intQuantity, intHoursWorked, curPayRate

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Constants—Named & Intrinsic  Using named constants follows conventional programming practice  Use named constants in lieu of “magic numbers” –increases documentation, –decreases likelihood of errors –facilitates global value changes –eases program maintenance

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill More about Constants  Examples of declaration: Const strRptName As string = “October Report” Const curTaxRate As Single =  Place constant declarations in lowest "covering level" you can.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Intrinsic Constants  Intrinsic constants are system-defined constants  They use a two-character prefix to indicate the source –vb means Visual Basic –db means Data Access Objects –xl means Excel

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Scope of Variables  Scope is the availability of a variable –Global: can always be used or seen across the entire project –Module: accessible by all procedures in the form –Local: accessible only from single procedure in which it is declared –Static: local variables that are “remembered” across invocations of a routine but not outside it

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Scope of Variables (continued)  Code module-level declarations in General Declarations section of a form.  Code Local and Static variables in subprocedures.  Variable's lifetime is the period of time that the variable exists.

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Calculations & the Val Function  Standard Operators: (), ^, *, /, +, -  Operator precedence determines how an equation is evaluated  Example: curTotal = curTotal + curLatest  Val function converts Text to value; reduces errors for blank entries in text box  Counting occurrences: intSum = intSum + 1

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Formatting Data  Alter the displayed form of a number or string by formatting it  Special format functions exist to speed the process including FormatPercent  Form of a typical format function: FormatCurrency(NumericExpressionToFormat)  FormatCurrency(curTotalDue)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Format Function Examples  lblTot.Caption = FormatCurrency(curTotal)  lblDate.Caption = FormatDateTime(intBirth)  lblQuantity.Caption = FormatNumber(intDone)  lblPercentDone.Caption = FormatPercent(txtDaysWork/txtTotalDays)

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Counting and Accumulating Sums  Counting: intCount = intCount + 1  Accumulating a sum: mintTotal = mintTotal + intNew  Averaging: msngAverage = mintTotalScore / intCount

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Calculation Program Example summary information