Download presentation
Presentation is loading. Please wait.
Published byDarren Osborne Modified over 9 years ago
1
Arrays
2
Lesson Objectives To understand what an array is and it’s function To know how code and array in VB
3
The Basics So we know what a variable is and how it can store one piece of information at one time, bit like a box You can insert something into the box. ‘name’ You can find out whats in the box by referencing The Problem The downside to this is that you have to declare lots of variable if you want to store lots of information
4
To the rescue There’s a way to get round this, and that’s arrays An array in its simplest form is a variable that has lots of slots in which you can store information, a bit like pigeonholes So the whole thing is an array with the slots being areas in which you can use
5
How does it work in VB So just like variables you have to declare the array and also specify the type of the array Dim myArray(10) As String Assigning to the array myArray(0) = ‘Hello’ Referencing the array myVar = myArray(0) Don’t forget that the indexes start at o (zero) This means that if you set up an array with 5 slots the first one is accessed using myArray(0) The number of slots you need
6
Multidimensional Arrays There are times in which it would be useful to sort more information, for example storing information about a set of people. 0123456 Single-Dimensional Array 0, 01, 02, 03, 04, 05, 06, 0 0, 11, 12, 13, 14, 15, 16, 1 0, 21, 22, 23, 24, 25, 26, 2 0, 31, 32, 33, 34, 35, 36, 3 0, 41, 42, 43, 44, 45, 46, 4 Multi-Dimensional Array First Dimension
7
Multidimensional Arrays Dim myArray(3, 2) As Integer Assigning to the array myArray(0, 1) = 132 Referencing the array myVar = myArray(0, 0) The same principles apply to a multidimensional array as they do to a single-dimension array TomJamesPeteJohn 132407583 4345
8
Challenges Bronze Challenge - Copy this program, to create and display a list of names. Each name should be printed to a new line. Silver Challenge - Create a multi-dimensional array to store the name and star sign of a group of students. Display a details for a random person when the program is run. Gold Challenge - Use a multi-dimensional array to store names & scores for these Strictly Come Dancing results.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.