Variables in VB.NET. Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can.

Slides:



Advertisements
Similar presentations
Tutorial 31 Variable Memory location whose value can change as the program is running. Used to hold temporary information Used to control the type of data.
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.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
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
Data Types and Expressions
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
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:
JavaScript, Third Edition
ITP 150 Week 4 Variables. ITP Lecturer: A. Borquez2 Review:  Controls  Propeties  Events  Methods  Procedures  Functions BackStyleFillColor.
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.
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 and Constants
Chapter 3: Using Variables and Constants
© 2006 ITT Educational Services Inc. Introduction to Computer Programming: Unit 2: Chapter 3: Slide 1 Unit 2 Variables and Calculations Chapter 3 Input,
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
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.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Representing Data: Constants and Variables CHAPTER THREE Matakuliah: T0063 – Pemrograman Visual Tahun: 2009.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
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.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Week 1-Visual Basic: Introduction HNDIT Rapid Application Development.
# 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
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
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.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 3: Using Variables.
Tutorial 3: Using Variables and Constants1 Tutorial 3 Using Variables and Constants.
Variables and Expressions Programming Right from the Start with Visual Basic.NET 1/e 7.
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. 
Chapter 2. Variable and Data type
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 3 Variables and Calculations.
Making Interactive Programs with Visual Basic .NET
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.
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.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
1.
Egyptian Language School Computer Department
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.
Visual Basic Variables
Visual Basic 6 (VB6) Data Types, And Operators
Data Types, Arithmetic Operations
2. Understanding VB Variables
Microsoft Visual Basic 2005 BASICS
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
CIS16 Application Development Programming with Visual Basic
Chapter 2: Java Fundamentals
Visual Basic Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

Variables in VB.NET

Variables  A storage location in memory (RAM)  Holds data/information while the program is running  These storage locations can be referred to by their names  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

Usage of Variables Copy and store values entered by the user Perform arithmetic manipulation on values Test values to see if they meet a criteria Temporarily hold and manipulate the value of a control property Hold data/information so that it can be recalled for use at a later point in the code

Choosing Data Type Data type - Specifies type of data variable can store Integer variables: Long, Integer, Short, Byte Floating-point variables: Single, Double Fixed decimal point variable: Decimal Boolean variables: True, False Character variable: Char Text variable: String The Object variable – Default data type assigned by Visual Basic – Can store many different types of data – Less efficient than other data types

Visual Basic Data Types Data typePrefixSizeValues Bytebyt1 bytepositive integer value from 0 to 255 Shortshr2 byteinteger from –32,768 to +32,767 Integerint4 byteinteger from +/- 2,147,483,647 Longlng8 byteinteger from +/- 9,223,372,036,854,775,807 Singlesng4 byte single-precision, floating-point number Doubledbl8 byte double-precision, floating-point number Decimaldec16 bytenumber with up to 28 significant digits Charchr2 byte Any single character Booleanbln2 byte True or False Stringstr(4 byte)Text - Any number/combination of characters Datedtm8 byte 8 character date: #dd/mm/yyyy# Objectobj(4 byte)An address that refers to an object

Variable Names  First character must be a letter or underscore  Must contain only letters, numbers, and underscores (no spaces, periods, etc.)  Can have up to 255 characters  Cannot be a VB language keyword  Naming Conventions  Should be meaningful  Follow 3 char prefix style - 1st 3 letters in lowercase to indicate the data type  After that, capitalize the first letter of each word  Example: intTestScore

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  Just append " = value” to the Dim statement  = 5  assigning a beginning value to the variable Example: Dim intLength as Integer = 5

Variable Declaration Rules Variable MUST be declared prior to the code where they are used Variable should be declared first in the procedure (style convention) Declaring an initial value of the variable in the declaration statement is optional

Default Values for Data Types Data typeDefault (Initial) value All numeric typesZero (0) BooleanFalse CharBinary 0 String or ObjectEmpty Date12:00 a.m. on January 1, 0001

Scope of Variables  What – Indicates the part of the program where the variable can be used  When – From the variable declaration until the end of the code block (procedure, method, etc.) where it is declared  Variable cannot be used before it is declared  Variable declared within a code block is only visible to statements within that code block ▪ Called Local Variable

Cont..,  Can be declared at the beginning of the class code window (General Declarations section) and be available to all blocks ▪ Called Form Level Variable  Variables that share the same scope cannot have the same name (same name ok if different scope)

Lifetime of Variables What – Indicates the part of the program where the variable exists in memory When – From the beginning of the code block (procedure, method, etc.) where it is declared until the end of that code block – When the code block begins the space is created to hold the local variables Memory is allocated from the operating system – When the code block ends the local variables are destroyed Memory is given back to the operating system

The End Thank you