Variables in VB Keeping Track. Variables Variables are named places in the computer memory that hold information. Variables hold only a single value at.

Slides:



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

Some computer fundamentals and jargon Memory: Basic element is a bit – value = 0 or 1 Collection of “n” bits is a “byte” Collection of several bytes is.
VBA for MS Excel Hamze Msheik. Open the Visual Basic Editor in Excel 2007 Click on the Microsoft Office button in the top left of the Excel window and.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
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.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
Data types and variables
1 Pertemuan 03 Representing Data Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Chapter 2 Data Types, Declarations, and Displays
VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.
String Escape Sequences
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.
Objectives You should be able to describe: Data Types
Binary Numbers. Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical attribute of a circuit,
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Data Representation.
Introduction to VB6 PPCC Course Winter 2004 Week 0 – Background Information Copyright ©2004, Tore Bostrup.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
VBA Lab 2 I ns.Samia Al-blwi. Visual Basic Grammar Object: Visual Basic is an object-oriented language. This means that all the items in Excel are thought.
Chapter 2: Using Data.
CPS120: Introduction to Computer Science
Lecture #5 Introduction to C++
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Primitive Variables.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Review With packagename ; Use packagename ; Procedure procedurename Is declaration of variables & constants Begin statements of program End procedurename.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Lecture 3 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout from Lecture 1 Background.
Programming with Microsoft Visual Basic th Edition
CSI 3125, Preliminaries, page 1 Data Type, Variables.
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
صياغة البرنامج Coding the Program. خرائط التدفق Flowchart ويطلق عليها أيضاً خرائط سير العمليات وهي مجموعة من الرموز المتعارف عليها تستخدم لتوضيح الخطوات.
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
Variables in VB. What is a variable? ► A named memory location that stores a value.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Primitive Data Types. int This is the type you are familiar with and have been using Stores an integer value (whole number) between -2,147,483,648 (-2.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
VBA - Excel VBA is Visual Basic for Applications
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
3.1 Denary, Binary and Hexadecimal Number Systems
Data Types, Arithmetic Operations
2. Understanding VB Variables
Microsoft Visual Basic 2005 BASICS
Chapter 6 Variables What is VBScript?
C++ Data Types Data Type
CS285 Introduction - Visual Basic
Storing Negative Integers
CHAPTER FOUR VARIABLES AND CONSTANTS
Introduction to Primitives
Introduction to Primitives
Variables and Constants
Presentation transcript:

Variables in VB Keeping Track

Variables Variables are named places in the computer memory that hold information. Variables hold only a single value at a time. Assigning a new value to them causes the old value to disappear. Values are assigned to a variable using an equals sign A = 5 assigns the value 5 to the variable A

What Variables Are Variables are named locations in memory. We could use 1’s and 0’s. Text Names are Easier or Grade_Average 8787

Memory with Variables Not Used String Integer Single Type

Looking at Contents System Memory fleeb 65 Address Name Value Type: Integer Contents

Variable Names Consist of letters, numbers and a few special characters. –They must begin with a letter. –They can’t have more than 40 letters –They can’t have an embedded period - this differentiates them from properties. –They can’t be names already in use. DimTrue False

Example Names Acceptable: Fred Fred_Flintstone Dimensional Times7 Unacceptable: Dim 7times Here.There There+Goes

What does mean? 65? “A” ? Nothing? Context is the difference between data and information. Variable Types give us context.

What are Variable Types? Context used to interpret data. A variable of type Integer holding is 65 because we view it as a binary number. A variable of type String holding is an “A” because we view it as an ASCII character.

ASCII Code used to represent characters. UNICODE is now being promoted as a replacement. ASCII does English (and Romance languages) UNICODE does all languages

Question: We know the binary value in a byte is: –A: The number 146 –B: The number 152 –C: The number 15.3 –D: The character ‘C’ –E: None of the Above

Variables in Visual Basic StringWidely used. IntegerWidely used. SingleWidely used. LongFrequently used. DoubleOccasionally used. CurrencyOccasionally used. VariantNot to be used.

Strings Hold character data Cannot be used for calculations. Are limited to between zero and approximately 2 billion letters. Use one byte per character plus 10 bytes for the string.

Integer Holds whole numbers (e.g. 1,2,3,4.....) Cannot hold fractional values (e.g. 3.2) Is limited to values between -32,768 and 32,767 Uses 2 bytes

Single “Single Precision Floating Point Number” Holds numbers with a decimal part Actually holds an approximation. –Difference is irrelevant for most purposes Is limited to values between – E38 to E-45 for negative numbers –1.401E-45 to 3.403E38 for positive numbers. Uses 4 bytes.

Question The number 8.5 can be stored in: A. An Integer B. A 35 gallon cooler, provided there is enough ice to prevent spoilage. C. A Single

Double “Double Precision Floating Point Number” Larger and More Precise Than Single Operations with these variables are much slower than with single precision. Is limited to values between –-1.798E308 to E-324 for negatives –4.9407E-324 to E308 for positive Uses 8 bytes

Long Long integers are used for storing larger integer values. Is limited to whole numbers from -2,147,483,648 to 2,147,483,647 Uses 4 bytes.

Currency Used to hold amounts of money. –A very long integer that has been shifted four decimal places to the right. –Gives 4 decimal places of accuracy. –Is limited to numbers with 4 decimal places of accuracy. Is limited to values between –-922,337,203,685, and 922,337,203,685,

Question The number 98,943 can be stored in: –A.An Integer –B.A Single –C.A Double –D.A Long –E.Currency

Variant This variable can become any of the other types, depending on the value assigned to it. We try not to use these because they can cause problems.

Get Explicit! Put Option Explicit in your code from the editor. Causes an error at compile time if you haven’t declared a variable.

Declaration of Variables The computer should know about variables before we use them. We do this using the declaration statement: Dim Fred As Single This declares one variable called Fred of type Single

More Declarations Dim Mary as Integer Dim Profit as Currency Dim FirstName as String

Question How many bytes does a variable of type single take? –A. 1 –B. 2 –C. 3 –D. 4 –E. 8

Object Variables A special kind of variable that holds portions of the Object Model. Workbooks, Worksheets, and Ranges are all examples Object variables have properties, identified by the period operator.

The Range Type The Range is an Object Variable Ranges have: –Value –Formula –Count –Interior

Declaring a Range Same as other variables: Dim r As Range Dim GivenRange as Range

Range Example Changing the Range’s Value: –GivenRange.Value = 5 Copying the value from one Range to another: OldRange.Value = NewRange.Value

Getting a Range Can be passed into a function. –Function Fleeb (R as Range) –user gives us R as a Range and we can refer to it. We can determine it ourselves Dim NewR as Range Set NewR = Worksheets(“S1”).Range(“A1”)

Worksheets Worksheet is another type of object variable. Worksheets have: –Range –Cells ActiveSheet is the sheet that is currently selected.

Using Worksheets Getting a cell from a Worksheet –Worksheet(“Sheet 1”).Cells(1,2) Getting a cell from the ActiveSheet –ActiveSheet.Cells(1,4)