Local variable values do not persist between calls to the method. Each time your
Timer1_Tick
method is called, all of the local variables will be set to their defaults.
You also don't have any code to retrieve the data - you're just adding
0
to the total each time.
You need to store the list of values in a field. Each time you add a new value, remove any values which are too old before you calculate the average.
A simple class to store the values might looks something like:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Public Class RollingAverage
Private ReadOnly _limit As Integer
Private _values As Queue(Of Double)
Public Sub New(ByVal limit As Integer)
_limit = limit
_values = New Queue(Of Double)
End Sub
Public Sub Add(ByVal value As Double)
If _values.Count = _limit Then
_values.Dequeue()
End If
_values.Enqueue(value)
End Sub
Public ReadOnly Property Count As Integer
Get
Return _values.Count
End Get
End Property
Public ReadOnly Property Average As Double
Get
Return _values.Average()
End Get
End Property
End Class
Store an instance of that class in a field, and use it to calculating the averages:
Private _averages As New RollingAverage(60)
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim data As Double = ... TODO: Get the data from somewhere ...
_averages.Add(data)
If _averages.Count = 60 Then
Average = _averages.Average
End If
End Sub