1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
Public Class OneCell
Public year As Integer
Public product As Integer
Public value As Integer
Public Sub New(ByVal y As Integer, ByVal p As Integer, ByVal v As Integer)
year = y
product = p
value = v
End Sub
End Class
Public Class MyStructure
Public listOfValues As System.Collections.ArrayList
Public Sub New()
listOfValues = New System.Collections.ArrayList
End Sub
Public Function getValue(ByVal y As Integer, ByVal p As Integer) As Integer
For Each c As OneCell In listOfValues
If c.year = y And c.product = p Then
Return c.value
End If
Next
Return -1
End Function
Public Sub setValue(ByVal y As Integer, ByVal p As Integer, ByVal v As Integer)
Dim found As Boolean = False
For Each c As OneCell In listOfValues
If c.year = y And c.product = p Then
found = True
c.value = c.value + v
End If
Next
If found = False Then
Dim c As OneCell = New OneCell(y, p, v)
listOfValues.Add(c)
End If
End Sub
End Class
Dim _list as MyStructure=new MyStructure()
Public Function SumAvg(Value as Integer, Year as Integer,Product as Integer)
_list.setValue(Year,product,value)
End Function
Public Function RetureSum(Year as Integer,Product as Integer) as Integer
Return _list.getValue(Year,Product)
End Function |
Partager