just some tinkering.....
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Dim Coll As New Collection
Public Structure Person
Public Name As String
Public Cash As Int32
End Structure
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim OrgArray(100, 1) As String
Dim RetArray(0, 0) As String
Dim InstanceOfPerson As Person
'Notice i have replaced "." with "," for the conversion from string to number to work properly.
OrgArray(0, 0) = "Jay"
OrgArray(0, 1) = "10,00"
OrgArray(1, 0) = "Jay"
OrgArray(1, 1) = "1,00"
OrgArray(2, 0) = "David"
OrgArray(2, 1) = "10,00"
OrgArray(3, 0) = "Erin"
OrgArray(3, 1) = "10,00"
OrgArray(4, 0) = "David"
OrgArray(4, 1) = "1,00"
'Make a collection to hold all the people and add the totals.
For i As Int16 = 0 To UBound(OrgArray, 1)
If OrgArray(i, 0) <> "" Then
With InstanceOfPerson
.Name = OrgArray(i, 0)
.Cash = CInt(OrgArray(i, 1))
End With
If Not ItemExistInCollection(InstanceOfPerson.Name) Then
Coll.Add(InstanceOfPerson, InstanceOfPerson.Name)
Else
InstanceOfPerson = Coll(OrgArray(i, 0))
InstanceOfPerson.Cash = InstanceOfPerson.Cash + CInt(OrgArray(i, 1))
Coll.Remove(InstanceOfPerson.Name)
Coll.Add(InstanceOfPerson, InstanceOfPerson.Name)
End If
End If
Next
'if where keep going to work with the collection all we have to do to loop tru then is
For Each InstanceOfPerson In Coll
Debug.WriteLine(InstanceOfPerson.Name & InstanceOfPerson.Cash)
Next
End Sub
Private Function ItemExistInCollection(ByVal Item As String) As Boolean
On Error Resume Next
Dim Ret As Object
Ret = Coll(Item)
If Ret <> "" Then
Return True
End If
Return False
End Function
End Class