### Map with Types

This example creates a Map with holds several items as a Type.
'Define the Type and the Map
`Sub Process_Globals
...
'Define the Contact Type
Type ContactType (Id As Int, Name As String, EMail As String)
'Define the contact map. Each entry is ID = ContactType
Private ContactMap As Map
...
End Sub`
Option 1
'Build the ContactMap holding ContactTypes
'Each Mapentry has as Key an Int and as Value a ContactType
`Sub BuildMap
ContactMap.Initialize
'Add some entries to the map
For i = 0 To 2
Dim Contact As ContactType
Contact.Initialize
Contact.Id = i
Contact.Name = "Name " & i
Contact.EMail = "email" & i & "@address.xyz"
'ID = ContactType
ContactMap.Put(i, Contact)
Next
End Sub`
'List the content of the ContactType
'Each Mapentry has as Key an Int and as Value a ContactType
'In the for each loop use the map values to get the contacts as contacttype
`Sub ListMap
For Each m As ContactType In ContactMap.Values
Log($"${m.Name} ${m.EMail} "$)
Next
End Sub`
Option 2 = This is an alternate option BUT Option 1 is better
'Add some test items to the map
`Sub MapAddItems
ContactMap.Initialize
For i = 0 To 2
Dim Contact As ContactType
Contact.Initialize
Contact.Id = i
Contact.Name = "Name " & i
Contact.EMail = "EMail" & i & "@address.xyz"
'ID = ContactType
ContactMap.Put(i, Contact)
Next
End Sub`
'List the map items using the ID
`Sub MapShowItems
For i = 0 To ContactMap.Size - 1
'Get the contact type from the map
Dim contact As ContactType = ContactMap.Get(i)
'Show the name and email
Log(contact.Name & " = " & contact.EMail)
Next
End Sub`

Changed: , Category: Map, File: T6C217M1601.htm, ID: 1601