Listbox - Looking at a specific range of data

I have a .csv file that populates into a list box and (with some much appreciated help from Tim), I extract and display stats such as; Max, Min, Average, Range, and Total of the entire data column (Column1). Now, I would like to take it further and run the stats on sections of the data. I would like to click DAILY, WEEKLY, OR MONTHLY buttons and have the stats update respectively. Example - I load 3 months of data but I would like to look at Daily stats of the data. I click the DAILY button and the stats update showing the first day (excluding the rest of the data). I would then click a NEXT button to look at the next day, and so on. This is scientific data from a logger and the CSV file looks like this:

01/26/2015 3:00 am, 1.97
01/26/2015 3:15 am, 3.97
01/26/2015 3:30 am, 0.88
… and so on

My current code for reading ALL of the data looks like this.

[code] Dim Sum, Mn, Mx, Rn, Avg, d As Double
Dim i, Size As Integer
Size = ListBox2.ListCount - 1
Sum = 0.0
For i = 0 To Size
d = CDbl(ListBox2.Cell(i, 1))
Sum = Sum + d
Mx = Max(Mx, d)
Mn = Min(Mn, d)
Rn = Mx-Mn
Avg = Sum/Size
if i = 1 then Mn = d // special case to initialize Min value


MainWindow.Maximum_Value.Text = Str(Mx, “###,###.##”)
MainWindow.Minimum_Value.Text= Str(Mn,"###,###.##")
MainWindow.Total_Value.Text=Str(Sum, “###,###.##”)
MainWindow.Range_Value.Text=Str(Rn, “###,###.##”)

Thanks in advance!


Add a property to the window, DateValue as Date. After you load the listbox, initialize DateValue with the date in the first row. You will use this date to isolate the Day/Week/Month in your loop.

dim s as string = Left(Listbox2.Cell(0,0), 10)
if not ParseDate(s, DateValue) then
   msgbox "Not a valid date in the first row"

Then in your code above, add a boolean flag dim ok as boolean and a date dim d as date. Add radiobuttons for Day, Month, Year.

For i = 0 to size
   ok  = true
   call ParseDate(left(me.Cell(row,0), 10), d)
   if DayRadioButton.Value = True then
      if d <> DateValue then ok = false
   if WeekRadioButton.Value = True then
      if d.WeekOfYear <> DateValue.WeekOfYear then ok = false
   if MonthRadioButton.Value = True then
      if d.Month <> DateValue.Month then ok = false
   if ok then
      // rest of your loop code

The code for the Next button is a little tricky if there are gaps in the data, but it could be as simple as

if DayRadioButton.Value = True then
   DateValue.Day = DateValue.Day + 1
if WeekRadioButton.Value = True then
   DateValue.Day = DateValue.Day + 7
if MonthRadioButton.Value = True
   DateValue.Month = DateValue.Month + 1