Variables in VB. What is a variable? ► A named memory location that stores a value.

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 2 Review Questions
VARIABLES: Your Own Piece of the ram. Why Use Variables? To save a piece of data in memory To save a piece of data in memory To store results of a calculation.
Variables and Constants
Variables in VB Keeping Track. Variables Variables are named places in the computer memory that hold information. Variables hold only a single value at.
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.
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
CIS 115 Lecture 5.  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can be referred.
VB DATATYPES, VARIABLES, CONSTANTS & CALCULATIONS.
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.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
2440: 211 Interactive Web Programming Expressions & Operators.
National Diploma Unit 4 Introduction to Software Development Data types, variables and constants.
VCE IT Theory Slideshows By Mark Kelly vceit.com Data Types 1 a.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Introduction to Pascal The Basics of Program writing.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
INT213-Week-2 Working with Variables. What is variable
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
# 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?
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
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.
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.
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.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
VCE IT Theory Slideshows By Mark Kelly vceit.com Version 2 – updated for 2016 Data Types 1 a.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 2. Program Construction in Java. 01 Java basics.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
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.
© 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.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
Use TryParse to Validate User Input
Chapter 2 Basic Computation
Programming constructs
Visual Basic Variables
Use TryParse to Validate User Input
Introduction to C++ October 2, 2017.
CHAPTER FOUR VARIABLES AND CONSTANTS
JavaScript.
B065: PROGRAMMING Variables 1.
Variables Here we go.
C# Revision Cards Data types
Data Types and Maths Programming Guides.
GCSE Computing:: Selection (IF statements)
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Variables and Constants
COMPUTING.
Presentation transcript:

Variables in VB

What is a variable? ► A named memory location that stores a value

Why use variables? ► Makes code easier to read ► Used to transfer information from one part of a program to another

Types of Variables TYPEPREFIX Singlesgl Doubledbl Integerint Longlng Currencycur Stringstr Booleanbln

Single ► Positive or negative real (might contain a decimal) numbers ► Can store smaller numbers

Double ► Same as single, but can store larger numbers

Integer ► Positive or negative integers (no decimals) ► Smaller integers ► Good for counting (e.g. number of students in a class) ► NOTE: if a decimal number is assigned to an integer, then the value is rounded ► E.g. 6.7 would become 7

Long ► Same as integer, but can store larger numbers

Currency ► Real numbers that are money values ► Up to four decimal places

String ► Set of characters (e.g. letters or any character that can be typed) ► String assignments require quotation marks “” ► E.g. strword = “hello”

Boolean ► True or false ► Used for on/off and yes/no values

Using Variables Step 1 – Declare Step 2 – Initialize (Assign a value) Step 3 – Use

Declaring Variables E.g. Dim intage As Integer ► Dim - stands for dimension (a variable has been assigned a space in memory somewhere) ► intage – identifier (name of variable) ► Integer – data type

Declaring Variables When a variable has been declared, you have saved a space in memory to hold whatever value is assigned: intage

Initializing Variables (assigning a value) E.g. intage = 15 OR intage = txtage.text This will assign whatever the user types into the textbox to intage.

Initializing Variables ► The space in memory now holds a value 15intage

Using the Variable E.g. intagedoubled = intage * 2 This will calculate the person’s age multiplied by 2 and then will store it in the variable called: intagedoubled. You can then output the variable intagedoubled to a textbox. txtagedoubled.text = intagedoubled

Questions 1 – Write a variable declaration statement for: a)A variable called intgrade of integer type b)A variable called strword of string type

Questions 2 – Indicate the value of the following variables: a) Dim dblnumber As Double dblnumber = 6 – 3 dblnumber dblnumber

Questions 2 – b) Dim intnum1 As Integer Dim intnum2 As Integer Dim intnum2 As Integer Dim intnum3 As Integer Dim intnum3 As Integer intnum1 = 3 intnum2 = 4 intnum3 = intnum1 * intnum2 intnum1 intnum2 intnum3