Ik heb de volgende code om een array te doorzoeken. Het lijkt goed te gaan, alleen ondanks de
"If InstanceofMyClass3.Hex = arrSBSRecord(4) Then" worden er toch nog records toegeveogd aan myarraylist.
Wellicht is er een veel slimmer manier om mijn probleem op te lossen (dan hoor ik dat ook graag ;-)) of er zit een fout in mijn code. Heeft iemand een idee?
Albert
Public Structure mystruct
Public Hex As String
Public Location As String
Public DateS As String
Public TimeS As String
Public Lat As String
Public Lng As String
Public Alt As String
Public Head As String
Public Callsign As String
Public Squawk As String
Public LastUpdate As String
End Structure
Dim myarraylist As New ArrayList()
Dim InstanceofMyClass As mystruct
'if no records in myarraylist add first received code.
If myarraylist.Count = 0 Then
If arrSBSRecord(1) = "1" Then
With InstanceofMyClass
.Hex = arrSBSRecord(4)
End With
End If
'add new record to myarraylist
myarraylist.Add(InstanceofMyClass)
myarraylist.TrimToSize()
Else
'loop through records (for = 0 To myarraylist.Count - 1
Gevonden = False
For i = 0 To myarraylist.Count - 1
InstanceofMyClass3 = CType(myarraylist(i), mystruct)
'If record allready exist in myarraylist then update Instance
If InstanceofMyClass3.Hex = arrSBSRecord(4) Then
Console.WriteLine("Update: " & InstanceofMyClass3.Hex)
'update instance
Gevonden = True
Exit For
End If
'If now record is found in myarraylist then add to myarraylist
If (Not Gevonden) And (i = 0) Then
If arrSBSRecord(1) = "1" Then
With InstanceofMyClass
.Hex = arrSBSRecord(4)
End With
myarraylist.Add(InstanceofMyClass)
myarraylist.TrimToSize()
End If
Exit For
End If
Next
End If
"If InstanceofMyClass3.Hex = arrSBSRecord(4) Then" worden er toch nog records toegeveogd aan myarraylist.
Wellicht is er een veel slimmer manier om mijn probleem op te lossen (dan hoor ik dat ook graag ;-)) of er zit een fout in mijn code. Heeft iemand een idee?
Albert
Public Structure mystruct
Public Hex As String
Public Location As String
Public DateS As String
Public TimeS As String
Public Lat As String
Public Lng As String
Public Alt As String
Public Head As String
Public Callsign As String
Public Squawk As String
Public LastUpdate As String
End Structure
Dim myarraylist As New ArrayList()
Dim InstanceofMyClass As mystruct
'if no records in myarraylist add first received code.
If myarraylist.Count = 0 Then
If arrSBSRecord(1) = "1" Then
With InstanceofMyClass
.Hex = arrSBSRecord(4)
End With
End If
'add new record to myarraylist
myarraylist.Add(InstanceofMyClass)
myarraylist.TrimToSize()
Else
'loop through records (for = 0 To myarraylist.Count - 1
Gevonden = False
For i = 0 To myarraylist.Count - 1
InstanceofMyClass3 = CType(myarraylist(i), mystruct)
'If record allready exist in myarraylist then update Instance
If InstanceofMyClass3.Hex = arrSBSRecord(4) Then
Console.WriteLine("Update: " & InstanceofMyClass3.Hex)
'update instance
Gevonden = True
Exit For
End If
'If now record is found in myarraylist then add to myarraylist
If (Not Gevonden) And (i = 0) Then
If arrSBSRecord(1) = "1" Then
With InstanceofMyClass
.Hex = arrSBSRecord(4)
End With
myarraylist.Add(InstanceofMyClass)
myarraylist.TrimToSize()
End If
Exit For
End If
Next
End If