SlideShare a Scribd company logo
1 of 3
Download to read offline
Lesson 7 of 8 Visual Basic Programming
1 of 3
Lesson 7: Mastering Arrays
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2020 April 10
Look at the code segment given below.
Dim num As Integer
num = 7
The variables that have been discussed so far can hold a single
value at a time. An array is a variable that can hold more than one
value at a time. Look at the code segment given below.
Dim nums (2) As Integer
nums (0) = 34
nums (1) = 58
nums (2) = 26
The array nums can hold three values. It can be graphically
represented as given below.
0 1 2
34 58 26
The index of each value is shown in red color. The value in 0th
index is 34, the value in 1st
index is 58, and the value in 2nd
index is
26.
Lesson 7 of 8 Visual Basic Programming
2 of 3
In order to declare an array that can hold three values, the code
segment Dim nums (2) As Integer was used. The maximum index of
the array should be specified within parenthesis.
Each value in the array can be displayed using the code segment
given below.
MessageBox.Show (“First Value: ” & nums (0))
MessageBox.Show (“Second Value: ” & nums (1))
MessageBox.Show (“Third Value: ” & nums (2))
Arrays can hold other types of data as well. An example for a
string array is given below.
Dim blood (3) As String
blood (0) = “Plasma”
blood (1) = “Red Blood Cells”
blood (2) = “White Blood Cells”
blood (3) = “Platelets”
0 1 2 3
Plasma Red Blood Cells White Blood Cells Platelets
Look at the code segment given below.
Dim nums () As Integer
Dim n As Integer
n = 10
ReDim nums (n)
Lesson 7 of 8 Visual Basic Programming
3 of 3
An array can be declared with empty parenthesis if the number
of values in the array is unknown at the beginning. Later using the
keyword ReDim, the number of values in the array can be specified.
Multidimensional arrays can also be declared. For an example, a
two-dimensional integer array is given below.
0 1 2 3
0 54 32 64 21
1 87 57 98 75
2 49 17 67 35
Dim array (2, 3) As Integer
Dim row, col As Integer
array (0, 0) = 54
array (0, 1) = 32
array (0, 2) = 64
array (0, 3) = 21
array (1, 0) = 87
array (1, 1) = 57
array (1, 2) = 98
array (1, 3) = 75
array (2, 0) = 49
array (2, 1) = 17
array (2, 2) = 67
array (2, 3) = 35
For row = 0 To 2
For col = 0 To 3
MessageBox.Show (array (row, col))
Next col
Next row

More Related Content

What's hot

Arrays In General
Arrays In GeneralArrays In General
Arrays In General
martha leon
 
Aae oop xp_05
Aae oop xp_05Aae oop xp_05
Aae oop xp_05
Niit Care
 
Cryptography an application of vectors and matrices
Cryptography an application of vectors and matricesCryptography an application of vectors and matrices
Cryptography an application of vectors and matrices
dianasc04
 

What's hot (20)

Lesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticLesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmetic
 
8
88
8
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
internal assement 3
internal assement 3internal assement 3
internal assement 3
 
6
66
6
 
Arrays and Pointers
Arrays and PointersArrays and Pointers
Arrays and Pointers
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
 
Plot function in R
Plot function in RPlot function in R
Plot function in R
 
Hill code
Hill codeHill code
Hill code
 
Maxterms
MaxtermsMaxterms
Maxterms
 
Arrays In General
Arrays In GeneralArrays In General
Arrays In General
 
Aae oop xp_05
Aae oop xp_05Aae oop xp_05
Aae oop xp_05
 
Cryptography an application of vectors and matrices
Cryptography an application of vectors and matricesCryptography an application of vectors and matrices
Cryptography an application of vectors and matrices
 
Chapter 4 number system
Chapter 4 number systemChapter 4 number system
Chapter 4 number system
 
Presentation of c 1
Presentation of c 1Presentation of c 1
Presentation of c 1
 
Bt9301, computer graphics
Bt9301, computer graphicsBt9301, computer graphics
Bt9301, computer graphics
 
International Journal of Engineering Research and Development
International Journal of Engineering Research and DevelopmentInternational Journal of Engineering Research and Development
International Journal of Engineering Research and Development
 
Matlab on basic mathematics
Matlab on basic mathematicsMatlab on basic mathematics
Matlab on basic mathematics
 
C programming enumeration
C programming enumerationC programming enumeration
C programming enumeration
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 

Similar to Arrays in Visual Basic Programming

C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
Princess Sam
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
AjayBahoriya
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Kumar Boro
 

Similar to Arrays in Visual Basic Programming (20)

Arrays in VbScript
Arrays in VbScriptArrays in VbScript
Arrays in VbScript
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
Lec 25 - arrays-strings
Lec 25 - arrays-stringsLec 25 - arrays-strings
Lec 25 - arrays-strings
 
Arrays
ArraysArrays
Arrays
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Structured Data Type Arrays
Structured Data Type ArraysStructured Data Type Arrays
Structured Data Type Arrays
 
Array and Collections in c#
Array and Collections in c#Array and Collections in c#
Array and Collections in c#
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer Graphics
 
Lecft3data
Lecft3dataLecft3data
Lecft3data
 
MODULE 5- EDA.pptx
MODULE 5- EDA.pptxMODULE 5- EDA.pptx
MODULE 5- EDA.pptx
 
C programming part4
C programming part4C programming part4
C programming part4
 
C programming part4
C programming part4C programming part4
C programming part4
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Aes128 bit project_report
Aes128 bit project_reportAes128 bit project_report
Aes128 bit project_report
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: Arrays
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 

More from Kasun Ranga Wijeweera

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 
An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#An Exercise for Factory Method Design Pattern in C#
An Exercise for Factory Method Design Pattern in C#
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 

Arrays in Visual Basic Programming

  • 1. Lesson 7 of 8 Visual Basic Programming 1 of 3 Lesson 7: Mastering Arrays Author: Kasun Ranga Wijeweera Email: krw19870829@gmail.com Date: 2020 April 10 Look at the code segment given below. Dim num As Integer num = 7 The variables that have been discussed so far can hold a single value at a time. An array is a variable that can hold more than one value at a time. Look at the code segment given below. Dim nums (2) As Integer nums (0) = 34 nums (1) = 58 nums (2) = 26 The array nums can hold three values. It can be graphically represented as given below. 0 1 2 34 58 26 The index of each value is shown in red color. The value in 0th index is 34, the value in 1st index is 58, and the value in 2nd index is 26.
  • 2. Lesson 7 of 8 Visual Basic Programming 2 of 3 In order to declare an array that can hold three values, the code segment Dim nums (2) As Integer was used. The maximum index of the array should be specified within parenthesis. Each value in the array can be displayed using the code segment given below. MessageBox.Show (“First Value: ” & nums (0)) MessageBox.Show (“Second Value: ” & nums (1)) MessageBox.Show (“Third Value: ” & nums (2)) Arrays can hold other types of data as well. An example for a string array is given below. Dim blood (3) As String blood (0) = “Plasma” blood (1) = “Red Blood Cells” blood (2) = “White Blood Cells” blood (3) = “Platelets” 0 1 2 3 Plasma Red Blood Cells White Blood Cells Platelets Look at the code segment given below. Dim nums () As Integer Dim n As Integer n = 10 ReDim nums (n)
  • 3. Lesson 7 of 8 Visual Basic Programming 3 of 3 An array can be declared with empty parenthesis if the number of values in the array is unknown at the beginning. Later using the keyword ReDim, the number of values in the array can be specified. Multidimensional arrays can also be declared. For an example, a two-dimensional integer array is given below. 0 1 2 3 0 54 32 64 21 1 87 57 98 75 2 49 17 67 35 Dim array (2, 3) As Integer Dim row, col As Integer array (0, 0) = 54 array (0, 1) = 32 array (0, 2) = 64 array (0, 3) = 21 array (1, 0) = 87 array (1, 1) = 57 array (1, 2) = 98 array (1, 3) = 75 array (2, 0) = 49 array (2, 1) = 17 array (2, 2) = 67 array (2, 3) = 35 For row = 0 To 2 For col = 0 To 3 MessageBox.Show (array (row, col)) Next col Next row