This document discusses using structures instead of arrays when different data types need to be stored together. It explains how to define a structure with multiple fields of different data types, create an array of that structure, and then access and assign values to the fields of each structure in the array. An example is given of modifying an existing table to instead use a structure to allow storing a team name along with the other data.
2. Data structure of array
We define an array as :
Dim myArray (10) as integer
To set up an integer array of 10 items with default values (= 0)
Or
MyArray = new integer(10) {}
To set up an integer array of 10 items with default values (=0)
Or
MyArray = new integer(10) {0,2,4,6,8,10,12,14,16,18}
To set up an integer array of 10 items with default values in the {}
3. For all of these, you can only use a single data type, such as :
Integer
Int16,
Int32
Double
String
You cannot have an array with mixed datatypes
4. What if we want to use
CustomerName, OrderCode,NumberOrdered
CustomerName is probably a STRING
OrderCode is probably a unique number OR unique Alpha-
numeric
NumberOrdered is probably an integer.
Mixed datatypes so cannot use an array.
5. Create our own data structure
WORK IN CONSOLE MODE.
1) Name the structure
Public Structure MyStructure
Public field as type
Public field as type
Public field as type
End Structure
) Repeat for as many fields
) as you need, using
) discrete names
6. If we know how many items
Create an array of MyStructure for that many items
If it is 8
Dim MyStructureArray(8) as MyStructure
To create 8 items in the array with default values.
Remember that to process this you use :
For items = 0 to 7 Zero based index
7. Putting a value into a structure
Array(x,y) = Value (You should know and be able to do this)
To put a value into a structure
MyStructureArray(index) . Fieldname = Value
As we set the structure up as an ARRAY, we use an index to point to the ROW
We then use DOT Notation, (a fullstop) that will display the fields in the
structure – select the one you want to work with.
Then assign a value with =value
8. You already have
Team Event1 Event2 Event3 LineTotal
1 1 1 3 5
3 2 3 2 7
2 3 2 3 8
How would you modify this to use a
structure to allow for TEAM NAME to
be entered?
Work in a team to discuss what your structure
will look like (10 minutes)
Then implement it