I have a gridview which is populated from a datasource, as such:
Date Hours
January/2016 26.31
January/2016 25.65
February/2016 12.3
.... ... ....
From that table I check for the weeks every month had and count them, so I can get an average later on, this is my code.
For intMonth = 1 To 12
For X = 0 To GridView.Rows.Count - 1
intDate = Convert.ToDateTime(gvTiempos.Rows(X).Cells(0).Text)
If DatePart("m", intDate) = intMonth Then
Calcular()
End If
Next
Next
This is the Calcular() function:
Public Function Calcular()
Select Case intMonth
Case 1: JanWeeks+=1
Case 2: FebWeeks+=1
...
Case 12: DecWeeks+=1
What I would like to do is to avoid the whole Calcular() function, and do it "dynamically".
In other words, I would like to get something like this:
Weeks(intMonth) = "Sum of Weeks for that month"
Where intMonth determinate in which WeekVariable the Sum will be storaged.
I have tried with the List(Of T) method unsuccessfully, because this creates a list of variables with a static value, according to my understanding.
Thanks in advance

colMonths(intMonth) +=1If you have a data source you should use that rather than the control. You could probably eveb write a linq query and get all 12(?) results at once. It also looks like you should turn on Option StrictWeeks(intMonth) = Weeks(intMonth) + 1. On a side note, you can eliminate this line:intDate = GridView.Rows(X).Cells(0).Text. It's value is not being used and you are reassigning it on the next line.Weeks(intMonth) = Weeks(intMonth) + 1it throwed this error: Index was out of range. Must be non-negative and less than the size of the collection.Dim Weeks(12) As Integer