SlideShare a Scribd company logo
Lesson 2 of 8 Visual Basic Programming
1 of 4
Lesson 2: Variables
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2020 May 08
A variable is a storage location in memory of the computer that holds
information while the program is running.
The statement that creates a variable in memory is called
declaration of the variable. An example code is given below.
Dim x As Byte
 Dim, As, Byte are keywords.
 x is the variable name.
 Byte is the data type.
 Byte data type holds unsigned 8-bit integers that range in value
from 0 to 255.
 The default value of Byte is 0.
The statement that assigns a value to a variable is called
initialization of the variable. An example code is given below.
x = 234
 The equals sign in the statement works as the assignment
operator not as the equality operator.
 The value on the right is assigned to the variable on the left.
0 0 0 0 0 0 0 0x
Lesson 2 of 8 Visual Basic Programming
2 of 4
 234 = 111010102
Data Types in Visual Basic
Integer Byte, Short, Integer, Long
Floating-Point Single, Double, Decimal
Other Boolean, Char, String, Date
Data Types to Store Integers
Dim age As Byte vs. Dim age As Long
Several bytes of memory can be saved by storing age in a Byte
instead in a Long.
Now look at the code segment given below.
Dim num1, num2, num3 As Integer
num1 = 24
num2 = 57
num3 = num1 + num2
MessageBox.Show (num3)
1 1 1 0 1 0 1 0
Data Type Size
Byte 8 bits
Short 16 bits
Integer 32 bits
Long 64 bits
x
Lesson 2 of 8 Visual Basic Programming
3 of 4
 The line Dim num1, num2, num3 As Integer creates three
memory blocks that hold default values.
num1 0
num2 0
num3 0
 The line num1 = 24 assigns the value 24 to the variable num1.
num1 24
num2 0
num3 0
 The line num2 = 57 assigns the value 57 to the variable num2.
num1 24
num2 57
num3 0
 The line num3 = num1 + num2 assigns the sum of the values of
the variables num1 and num2 to the variable num3.
num1 24
num2 57
num3 81
Lesson 2 of 8 Visual Basic Programming
4 of 4
 The line MessageBox.Show (num3) displays the value of the
variable num3 in a message box.
 Note that an assignment changes only the left operand while the
right operand remains unchanged.
Rules for Variable Naming
 The first character of a variable name must be either a letter
or an underscore.
 Subsequent characters must be a letter, underscore, or digit.
 Variable names cannot contain spaces, periods, or many other
kinds of characters.
 The keywords in Visual Basic cannot be used as variable
names.
Ad

Recommended

Operators in python
Operators in python
eShikshak
 
Vbscript
Vbscript
VARSHAKUMARI49
 
string manipulation in python ppt for grade 11 cbse
string manipulation in python ppt for grade 11 cbse
KrithikaTM
 
Python Modules
Python Modules
Nitin Reddy Katkam
 
Variables in C and C++ Language
Variables in C and C++ Language
Way2itech
 
Scope rules : local and global variables
Scope rules : local and global variables
sangrampatil81
 
Python: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
VB.net
VB.net
PallaviKadam
 
Python dictionary
Python dictionary
Mohammed Sikander
 
Pointers in c++
Pointers in c++
sai tarlekar
 
Python array
Python array
Arnab Chakraborty
 
Function C programming
Function C programming
Appili Vamsi Krishna
 
Loops in java script
Loops in java script
Ravi Bhadauria
 
Chapter 02 php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
Packages - PL/SQL
Packages - PL/SQL
Esmita Gupta
 
Java String class
Java String class
DrRajeshreeKhande
 
Python programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
File handling in Python
File handling in Python
Megha V
 
Array Of Pointers
Array Of Pointers
Sharad Dubey
 
Array in c#
Array in c#
Prem Kumar Badri
 
pointers
pointers
teach4uin
 
Arrays in python
Arrays in python
moazamali28
 
Tokens expressionsin C++
Tokens expressionsin C++
HalaiHansaika
 
Python exception handling
Python exception handling
Mohammed Sikander
 
Cursors
Cursors
Priyanka Yadav
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Python variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Templates in c++
Templates in c++
Mayank Bhatt
 
Matlab numbers
Matlab numbers
pramodkumar1804
 
Data-and-Number-Representations CSE 101.pptx
Data-and-Number-Representations CSE 101.pptx
mb8841487
 

More Related Content

What's hot (20)

Python dictionary
Python dictionary
Mohammed Sikander
 
Pointers in c++
Pointers in c++
sai tarlekar
 
Python array
Python array
Arnab Chakraborty
 
Function C programming
Function C programming
Appili Vamsi Krishna
 
Loops in java script
Loops in java script
Ravi Bhadauria
 
Chapter 02 php basic syntax
Chapter 02 php basic syntax
Dhani Ahmad
 
Packages - PL/SQL
Packages - PL/SQL
Esmita Gupta
 
Java String class
Java String class
DrRajeshreeKhande
 
Python programming : Control statements
Python programming : Control statements
Emertxe Information Technologies Pvt Ltd
 
File handling in Python
File handling in Python
Megha V
 
Array Of Pointers
Array Of Pointers
Sharad Dubey
 
Array in c#
Array in c#
Prem Kumar Badri
 
pointers
pointers
teach4uin
 
Arrays in python
Arrays in python
moazamali28
 
Tokens expressionsin C++
Tokens expressionsin C++
HalaiHansaika
 
Python exception handling
Python exception handling
Mohammed Sikander
 
Cursors
Cursors
Priyanka Yadav
 
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Python variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Templates in c++
Templates in c++
Mayank Bhatt
 

Similar to Variables in Visual Basic Programming (20)

Matlab numbers
Matlab numbers
pramodkumar1804
 
Data-and-Number-Representations CSE 101.pptx
Data-and-Number-Representations CSE 101.pptx
mb8841487
 
Computer Oraganizaation.pptx
Computer Oraganizaation.pptx
bmangesh
 
Session2
Session2
daviessegera
 
Bit-Manipulation for competitive programming
Bit-Manipulation for competitive programming
gaurav77712
 
chapter one && two.pdf
chapter one && two.pdf
miftah88
 
Arrays in Visual Basic Programming
Arrays in Visual Basic Programming
Kasun Ranga Wijeweera
 
Cmps290 classnoteschap02
Cmps290 classnoteschap02
HussnainSarmad
 
Lec 02 data representation part 1
Lec 02 data representation part 1
Abdul Khan
 
Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...
PVS-Studio
 
Data representation computer architecture
Data representation computer architecture
study cse
 
Topic 1 Data Representation
Topic 1 Data Representation
Kyle
 
Topic 1 Data Representation
Topic 1 Data Representation
ekul
 
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
Andrey Karpov
 
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
PVS-Studio
 
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
Andrey Karpov
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
umardanjumamaiwada
 
Csc 2313 (lecture 3)
Csc 2313 (lecture 3)
umardanjumamaiwada
 
Visual Basics for Application
Visual Basics for Application
Raghu nath
 
Data representation _
Data representation _
SwatiHans10
 
Data-and-Number-Representations CSE 101.pptx
Data-and-Number-Representations CSE 101.pptx
mb8841487
 
Computer Oraganizaation.pptx
Computer Oraganizaation.pptx
bmangesh
 
Bit-Manipulation for competitive programming
Bit-Manipulation for competitive programming
gaurav77712
 
chapter one && two.pdf
chapter one && two.pdf
miftah88
 
Cmps290 classnoteschap02
Cmps290 classnoteschap02
HussnainSarmad
 
Lec 02 data representation part 1
Lec 02 data representation part 1
Abdul Khan
 
Development of a static code analyzer for detecting errors of porting program...
Development of a static code analyzer for detecting errors of porting program...
PVS-Studio
 
Data representation computer architecture
Data representation computer architecture
study cse
 
Topic 1 Data Representation
Topic 1 Data Representation
Kyle
 
Topic 1 Data Representation
Topic 1 Data Representation
ekul
 
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
Andrey Karpov
 
20 issues of porting C++ code on the 64-bit platform
20 issues of porting C++ code on the 64-bit platform
PVS-Studio
 
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
Program errors occurring while porting C++ code from 32-bit platforms on 64-b...
Andrey Karpov
 
Visual Basics for Application
Visual Basics for Application
Raghu nath
 
Data representation _
Data representation _
SwatiHans10
 
Ad

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#
Kasun Ranga Wijeweera
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#
Kasun Ranga Wijeweera
 
Introduction to Design Patterns
Introduction to Design Patterns
Kasun Ranga Wijeweera
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
Kasun Ranga Wijeweera
 
Geometric Transformations II
Geometric Transformations II
Kasun Ranga Wijeweera
 
Geometric Transformations I
Geometric Transformations I
Kasun Ranga Wijeweera
 
Introduction to Polygons
Introduction to Polygons
Kasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
Kasun Ranga Wijeweera
 
Conditional Logic: Exercises
Conditional Logic: Exercises
Kasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
Kasun Ranga Wijeweera
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtons
Kasun Ranga Wijeweera
 
Loops in Visual Basic Programming
Loops in Visual Basic Programming
Kasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
Kasun Ranga Wijeweera
 
Assignment for Variables
Assignment for Variables
Kasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Kasun Ranga Wijeweera
 
Assignment for Events
Assignment for Events
Kasun Ranga Wijeweera
 
Mastering Arrays Assignment
Mastering Arrays Assignment
Kasun Ranga Wijeweera
 
An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#
Kasun Ranga Wijeweera
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
Kasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
Kasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Kasun Ranga Wijeweera
 
An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#
Kasun Ranga Wijeweera
 
Ad

Recently uploaded (20)

Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
Top Time Tracking Solutions for Accountants
Top Time Tracking Solutions for Accountants
oliviareed320
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Sap basis role in public cloud in s/4hana.pptx
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Automated Testing and Safety Analysis of Deep Neural Networks
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Complete Guideliness to Build an Effective Maintenance Plan.ppt
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
declaration of Variables and constants.pptx
declaration of Variables and constants.pptx
meemee7378
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
On-Device AI: Is It Time to Go All-In, or Do We Still Need the Cloud?
Hassan Abid
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
Top Time Tracking Solutions for Accountants
Top Time Tracking Solutions for Accountants
oliviareed320
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
Sap basis role in public cloud in s/4hana.pptx
Sap basis role in public cloud in s/4hana.pptx
htmlprogrammer987
 
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
Enable Your Cloud Journey With Microsoft Trusted Partner | IFI Tech
IFI Techsolutions
 
Automated Testing and Safety Analysis of Deep Neural Networks
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Complete Guideliness to Build an Effective Maintenance Plan.ppt
Complete Guideliness to Build an Effective Maintenance Plan.ppt
QualityzeInc1
 
declaration of Variables and constants.pptx
declaration of Variables and constants.pptx
meemee7378
 
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 [Latest 2025]
HyperPc soft
 
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Test Case Design Techniques – Practical Examples & Best Practices in Software...
Muhammad Fahad Bashir
 
Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
IDM Crack with Internet Download Manager 6.42 Build 41 [Latest 2025]
pcprocore
 

Variables in Visual Basic Programming

  • 1. Lesson 2 of 8 Visual Basic Programming 1 of 4 Lesson 2: Variables Author: Kasun Ranga Wijeweera Email: [email protected] Date: 2020 May 08 A variable is a storage location in memory of the computer that holds information while the program is running. The statement that creates a variable in memory is called declaration of the variable. An example code is given below. Dim x As Byte  Dim, As, Byte are keywords.  x is the variable name.  Byte is the data type.  Byte data type holds unsigned 8-bit integers that range in value from 0 to 255.  The default value of Byte is 0. The statement that assigns a value to a variable is called initialization of the variable. An example code is given below. x = 234  The equals sign in the statement works as the assignment operator not as the equality operator.  The value on the right is assigned to the variable on the left. 0 0 0 0 0 0 0 0x
  • 2. Lesson 2 of 8 Visual Basic Programming 2 of 4  234 = 111010102 Data Types in Visual Basic Integer Byte, Short, Integer, Long Floating-Point Single, Double, Decimal Other Boolean, Char, String, Date Data Types to Store Integers Dim age As Byte vs. Dim age As Long Several bytes of memory can be saved by storing age in a Byte instead in a Long. Now look at the code segment given below. Dim num1, num2, num3 As Integer num1 = 24 num2 = 57 num3 = num1 + num2 MessageBox.Show (num3) 1 1 1 0 1 0 1 0 Data Type Size Byte 8 bits Short 16 bits Integer 32 bits Long 64 bits x
  • 3. Lesson 2 of 8 Visual Basic Programming 3 of 4  The line Dim num1, num2, num3 As Integer creates three memory blocks that hold default values. num1 0 num2 0 num3 0  The line num1 = 24 assigns the value 24 to the variable num1. num1 24 num2 0 num3 0  The line num2 = 57 assigns the value 57 to the variable num2. num1 24 num2 57 num3 0  The line num3 = num1 + num2 assigns the sum of the values of the variables num1 and num2 to the variable num3. num1 24 num2 57 num3 81
  • 4. Lesson 2 of 8 Visual Basic Programming 4 of 4  The line MessageBox.Show (num3) displays the value of the variable num3 in a message box.  Note that an assignment changes only the left operand while the right operand remains unchanged. Rules for Variable Naming  The first character of a variable name must be either a letter or an underscore.  Subsequent characters must be a letter, underscore, or digit.  Variable names cannot contain spaces, periods, or many other kinds of characters.  The keywords in Visual Basic cannot be used as variable names.