Visual Basic Variables

Slides:



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

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
JavaScript, Fourth Edition
JavaScript, Third Edition
VB .NET Programming Fundamentals
CIS 115 Lecture 5.  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can be referred.
Variables and Constants
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3 Part 11 Variables, Constants, and Calculations Chapter 3 Section 3.3 Chapter 3 Section 3.4.
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?
Chapter 2: Using Data.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
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.
CHAPTER 4 GC 101 Data types. DATA TYPES  For all data, assign a name (identifier) and a data type  Data type tells compiler:  How much memory to allocate.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
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.
Primitive Variables.
Chapter 2 Variables.
Chapter 51 Logical Operators Used with Boolean expressions Not – makes a False expression True and vice versa And – will yield a True if and only if both.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Data And Variables Chapter Names vs. Values Michael Jordan name (the letter sequence used to refer to something) value (the thing itself)
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.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
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.
© 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.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1.
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Chapter 2 Basic Computation
Identifiers - symbolic names
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
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Revision Lecture
Variables, Expressions, and IO
Identifiers - symbolic names
Building Java Programs Chapter 2
Introduction to C++ Programming
Numbers.
Chapter 2 Variables.
elementary programming
Data Types and Expressions
Primitive Types and Expressions
Unit 3: Variables in Java
Visual Basic Variables
Chapter 2 Variables.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Data Types and Expressions
Data Types and Expressions
Introduction to Python
Presentation transcript:

Visual Basic Variables Chapter 2 Visual Basic Variables 1

Variables A Every variable has three properties: Name - reference to the location - cannot be changed Value - the information that is stored - can be changed during program execution, hence the name “variable” Data Type - the type of information that can be stored - cannot be changed 2

Choosing Data Type Data type - Specifies type of data variable can store Integer variables: Integer Floating-point variables: Double Boolean variables: True, False Character variable: Char Text variable: String

Variable Names First character must be a letter or underscore Must contain only letters, numbers, and underscores (no spaces, periods, etc.) Naming Conventions Should be meaningful capitalize the first letter of each word Example: testScore

Declaring a Variable A variable declaration is a statement that creates a variable in memory Syntax: Dim VariableName As DataType Dim (short for Dimension) - keyword VariableName - name used to refer to variable As - keyword DataType - one of many possible keywords to indicate the type of value the variable will contain Example: Dim intLength as Integer

Declaring and Initializing a Variable A starting or initialization value may be specified with the Dim statement Good practice to set an initial value unless assigning a value prior to using the variable Syntax: Dim VariableName As DataType = Value OR Dim VariableName As DataType VariableName = Value Example: Dim intLength as Integer = 5 Dim intLength as Integer intLength=5 6

Variables Types Integer Char Double String

Variable Declaration Rules Variable MUST be declared before the code where they are used Declaring an initial value of the variable in the declaration statement is optional 8

Type Integer: 5 ; 157 ; Double : 195.38256 String: “Paul” ; “Hello!!!” ; “Jackson, AL 36545” Char: ‘a’ ; ‘1’ ; ‘?’ ; ‘@’ Boolean: True ; False 9

Assignment Statement Syntax: variablename = expression Assigns the value of the expression to the variable. (The variable must be on the left and the expression on the right.) Example: intNumber1 = 4 intNumber2 = 3 * (2 + 2) intNumber3 = intNumber1 IntNumber1 = intNumber1 + 6 10

Performing Calculations with Variables Arithmetic Operators ^ Exponential * Multiplication / Floating Point Division MOD Modulus (remainder from division) + Addition – Subtraction 11

Special Modulus Operator This operator can be used in place of the backslash operator to give the remainder of a division operation intRemainder = 17 MOD 3 ‘result is 2 dblRemainder = 17.5 MOD 3 ‘result is 2.5 Any attempt to use of the \ or MOD operator to perform integer division by zero causes a DivideByZeroException runtime error 12

Combined Assignment Operators Often need to change the value in a variable and assign the result back to that variable For example: var = var – 5 Subtracts 5 from the value stored in var Operator Usage Equivalent to Effect += x += 2 x = x + 2 Add to -= x -= 5 x = x – 5 Subtract from *= x *= 10 x = x * 10 Multiply by /= x /= y x = x / y Divide by 13

Arithmetic Operator Precedence Operator precedence tells us the order in which operations are performed Parentheses () override the order of precedence From highest to lowest precedence: Exponentiation (^) Multiplicative (* and /) Modulus (MOD) Additive (+ and -) Where precedence is the same, operations occur from left to right

All Operators Precedence Parenthesis () Exponential Multiplication / Division MOD Addition / Subtraction 15

Precedence Examples 6 * 2 ^ 3 + 4 / 2 = 50 7 * 4 / 2 – 6 = 8 5 * (4 + 3) – 15 Mod 2 = 34 intX = 10 intY = 5 intResultA = intX + intY * 5 'iResultA is 35 iResultB = (intX + intY) * 5 'iResultB is 75 dResultA = intX - intY * 5 'dResultA is -15 dResultB = (intX - intY) * 5 'dResultB is 25 16