Variables Continued In the last session we saw how variables are objects that allow us to store values in the RAM of the computer In this session we shall.

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.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Python November 14, Unit 7. Python Hello world, in class.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 05 Learning To Program.
Rote Learning of the Week "A variable is a named section of RAM that stores data of a specific data type"
A Level Computing#BristolMet Session ObjectivesU2#S10 MUST describe the difference between constants, local and global variables SHOULD explain why constants.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Variables "There are 10 kinds of people in the world today – those who understand binary and those who don't!” Unknown.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Equation Jeopardy Add Mixed Multiply/ Divide Fractions Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy Subtract.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Variables and Math in Code. Variables A variable is a storage block for information in your program “A” “A” Computer Program Memory Computer Program.
Class 3 Remote Instruction Computer Math EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure your volume is.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
22/11/ Selection If selection construct.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
INT213-Week-2 Working with Variables. What is variable
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Pay Example (PFirst98) Please use speaker notes for additional information!
COMPUTER PROGRAMMING I SUMMER Apply operators and Boolean expressions.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
CECS 5020 Computers in Education Visual Basic Variables and Constants.
31/01/ Selection If selection construct.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
Controlling Program Flow with Decision Structures.
Variables in VB. What is a variable? ► A named memory location that stores a value.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
Data Handling in Algorithms. Activity 1 Starter Task: Quickly complete the sheet 5mins!
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Making Interactive Programs with Visual Basic .NET
© 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.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
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.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Objects Allow us to represent and control the computer technology Use methods to make the object do something Use properties to find out and change the.
Input, Output and Variables GCSE Computer Science – Python.
Data Types Mr Tottman Link. Data Types Programs need to use data for calculations and for output to various devices The best programs will always use.
Egyptian Language School Computer Department
A variable is a name for a value stored in memory.
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Data Types, Arithmetic Operations
Variables Data Types and Assignment
Conditions and Ifs BIS1523 – Lecture 8.
Numbers.
23 ×
CHAPTER FOUR VARIABLES AND CONSTANTS
Introduction to Primitives
Variables Data Types and Assignment
Unit 3: Variables in Java
Variables Data Types and Assignment
Input, Variables, and Mathematical Expressions
COMPUTING.
Python Creating a calculator.
Presentation transcript:

Variables Continued In the last session we saw how variables are objects that allow us to store values in the RAM of the computer In this session we shall take a look at: Some other variable data types Different tasks you may perform with different data types

Additional Data Types The following code is taken from the Widget Swap program (btnSave of aswap.aspx). Notice some new data types.

The Date Data Type What if I asked you to add 200 days to today’s date? In VB.NET using the date data type it is easy... Dim MyDate As Date Dim NewDate As Date MyDate = "23/4/2010" NewDate = MyDate.AddDays(200)

The Decimal, Integer & Byte Data Types All numeric data types. They differ in the kinds of number they store Byte and Integer may only store whole numbers Byte cannot store negative numbers and is limited to a range of 0 to 255 Integer has a range from -2,147,483,648 to 2,147,483,647 but like byte cannot store decimals If we want to store larger numbers than those above or want to store decimal values e.g. currency we need to use the decimal data type. The decimal data type has a range of +/- 79,228,162,514,264,337,593,543,950,335

Rounding Decimal Numbers Since the decimal data type tends to go a bit over the top with the number of decimal places it is worth knowing how to round decimal numbers. The Math.Round method will do this. Dim Price As Decimal Price = txtPrice.Text = Math.Round(Price, 2) The above code would round the price to 2 decimal places.

Mathematical Processing Addition. Addition operator.+ Dim MyVariable As Integer MyVariable = Subtraction. Subtraction operator- Dim MyVariable As Integer MyVariable = 5 – 2 Multiplication. The multiplication operator* Dim MyVariable As Integer MyVariable = 15 * 2 Division. The division operator / Dim MyVariable As Integer MyVariable = 30 / 2

The String Data Type & Concatenation Concatenation involves the joining together of smaller strings to form larger strings.

The Boolean Data Type The Boolean data type is used to store the results of Boolean logic that is based only on the values True and False. Boolean variables may only store either True or False. Later in the module we shall use the validation function called IsNumeric which we will use to check if something is a number or not. The following code gives you some idea of how it works... Dim OK As Boolean OK = IsNumeric("Fred")

Why don’t we just use Controls and Abandon Variables? Take a look at the following code… Why don’t we just rewrite the code as follows?

Two Reasons Controls have a visual component they are more demanding on system resources. A variable is a much more “light weight” object. Any code that constantly uses controls to perform processing will run slower than the same code written using variables. Controls are typeless and run the risk of producing strange results.

Unexpected Results Imagine we have the following program that adds two numbers together. What do you expect will happen when we press Add? The click event for “Add” contains the following code...

The Result… The problem is that instead of performing a numeric operation the code performs a string operation. It concatenates rather than adds. This is one example of the unpredictable results that may happen if we use controls and not variables.

Questions 1. What is wrong with the following variable declarations? Dim My Name As String Dim MyName As Integer Dim Age As Decimal Dim Price As Byte Dim Password As Boolean Dim OK As Integer

Questons 2. Plan out a program that takes two numbers, multiplies them and displays the result. What inputs are required? What outputs are required? Declare the variables for the inputs and outputs Assign values to the input variables Write the code that calculates the answer Display the result on the web form