Stephan Dijkxhoorn
asked on
How to iterate a Dictionary(Of Integer, List(Of MyClass))
Hello there,
I am experiencing some severe problems, when trying to iterate a dictionary of type Dictionary(Of Integer, List (Of clsMyClass) ).
How can I access the list in a single Dictionary object ?
I am experiencing some severe problems, when trying to iterate a dictionary of type Dictionary(Of Integer, List (Of clsMyClass) ).
How can I access the list in a single Dictionary object ?
Public Sub TestMe()
Dim EOL As String = vbCrLf
Dim strText = System.IO.File.ReadAllText(_FileName)
Dim _lines As String()
_lines = Split(strText, EOL)
Dim EDIFileReferences As New Dictionary(Of Integer, List(Of clsEDI_FileImportMappingClass))
'(1)
For row As Integer = 0 To _lines.Count - 1
Dim line As String
line = _lines(row)
Dim SEGMDESC As String = Left(line, 3)
Dim Filter As String = line.Substring(3, 2)
Dim Mapping As List(Of clsEDI_FileImportMappingClass) = Profil.getEdiSegCols(SEGMDESC, Filter)
Dim x As New List(Of clsEDI_FileImportMappingClass)
x = MapContentsOfImportedEdiFile(line, Mapping)
EDIFileReferences.Add(row, New List(Of clsEDI_FileImportMappingClass))
EDIFileReferences(row) = x
Next
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' (2) Following fragment is showing only identical contents:
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
For row As Integer = 0 To EDIFileReferences.Count - 1
Dim objList As List(Of clsEDI_FileImportMappingClass) = EDIFileReferences(row)
Dim sout As String : sout = ""
For x As Integer = 0 To EDIFileReferences(row).Count - 1
sout = "ROW IN FILE: " & row.ToString & " | SEGMENT: " & EDIFileReferences(row).Item(x).SEGMENT & " | FELD-NR.:" & EDIFileReferences(row).Item(x).EDI_FIELD & " | CONTENTS: " & EDIFileReferences(row).Item(x).CONTENTS.ToString
Debug.Print(sout)
Next
Next
End Sub
' *****************************************************
Public Function MapContentsOfImportedEdiFile(ByVal csvline As String, ByVal ediDBObjMapping As List(Of clsEDI_FileImportMappingClass)) As List(Of clsEDI_FileImportMappingClass)
Dim x As New List(Of clsEDI_FileImportMappingClass)
' Processing ediDBObjMapping
' Return mapped contents
Return x
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a working solution and there was no connection to your answer, Fernando.
Hi Stephan;
The solution you selected does not even handle the case you gave in the question having a dictionary of in't list of objects we're mine does how come you selected that solution can you explain please.
The solution you selected does not even handle the case you gave in the question having a dictionary of in't list of objects we're mine does how come you selected that solution can you explain please.
This is how to iterate through the List stored in the Dictionary object.
Open in new window