Escolar Documentos
Profissional Documentos
Cultura Documentos
Arrays
A simple or scalar variable is one that is unrelated to any other variable in memory
An array is a group of variables that have the same name and data type and are related in some way
Arrays (continued)
The most commonly used arrays are onedimensional and two-dimensional
Programmers use arrays to store related data in the internal memory of the computer
One-Dimensional Arrays
A one-dimensional array is simply a row (or column) of variables
Each element in an array is identified by a subscript, which Visual Basic .NET assigns to the variable when the array is created
Examples
cities(0) = Madrid cities(1) = Paris cities(2) = Rome
10
11
12
13
14
15
uiSalaryButtons Click event procedure displays the salary corresponding to the code entered by the user
16
17
18
19
20
21
dimensional array in ascending order Syntax: Array.Sort(arrayname) uiSortButtons Click event procedure uses the Array.Sort method to sort the numbers array in ascending order
Programming with Microsoft Visual Basic .NET, Second Edition
22
23
Should give the user the choice of displaying the names in either ascending or descending order
The names array is declared in the forms Declarations section, making it a module-level array
Programming with Microsoft Visual Basic .NET, Second Edition
24
25
26
27
Structures
Structure statement: can be used to create your own data types in Visual Basic .NET
Data types created using the Structure statement are referred to as user-defined data types or structures Members included in the structure can be variables, constants, or procedures In most cases, members are variables
Programming with Microsoft Visual Basic .NET, Second Edition
28
Structures (continued)
29
30
31
32
33
Two-Dimensional Arrays
A two-dimensional array resembles a table in that the variables are in rows and columns
34
35
36
Figure 10-35: Syntax and examples of entering data into a twodimensional array
Programming with Microsoft Visual Basic .NET, Second Edition
37
38
Figure 10-36: uiDisplayPriceButtons Click event procedure using a twodimensional array (continued)
Programming with Microsoft Visual Basic .NET, Second Edition
39
40
41
42
43
Figure 10-41: Pseudocode for the uiCalculateButtons Click event procedure (continued)
Programming with Microsoft Visual Basic .NET, Second Edition
44
Summary
Two versions of the syntax used to declare a one-dimensional array:
{Dim | Private} arrayname(highestSubscript) As datatype {Dim | Private} arrayname() As datatype = {initialValues}
45
Summary (continued)
To refer to a variable in an array, use the arrays name followed by the variables subscript
To create parallel one-dimensional arrays, create two one-dimensional arrays To create an array of structures, use the Structure statement to create a record structure, then use the record structure to declare the array
46
Summary (continued)
Two versions of the syntax used to declare a two-dimensional array:
{Dim | Private} arrayname(highestRowSubscript, highestColumnSubscript) As datatype {Dim | Private} arrayname(,) As datatype = {{initialValues}, {initialValues},{initialValues}}
47