Если вы просто хотите использовать min, max, mean, вам не нужно хранить значения во временном массиве. Смотрите пример ниже. Кроме того, будьте осторожны, чтобы написать pHData(j).Dy
, а не pHData.Dy(j)
.
For i = LBound(uniqueArr) to UBound(uniqueArr)
' Re-initialise min, max, sum
phMin = VeryLargeNumber ' Choice of VeryLargeNumber depends on your application.
phMax = - VeryLargeNumber ' Make it beyond the range of possible pH values.
phSum = 0
phCount = 0
For j = LBound(pHData) to UBound(pHData)
With phData(j)
If .Dy== uniqueArr(i)
' These will be used to calculate the mean later
phCount = phCount + 1
phSum = phSum + .pH
' Is this the max or min so far?
If .pH > phMax Then
' This is the largest pH value encountered so far
phMax = .pH
ElseIf .pH < phMin Then
' This is the smallest pH value encountered so far
phMin = .pH
Else
' This pH value is neither the largest nor smallest encountered so far.
' Do nothing.
End If
Else
' This measurement was not taken on this date.
' Do nothing.
End If
End With
phMean = phSum / phCount
' Here goes some code to store this date's
' min, max, and mean somewhere convenient.
Next j
Next i
Если вы действительно хотите хранить вещи во временном массиве, код будет более запутанным, а также более медленным ... Вот так:
Dim todaysValues() As [Whatever type you need]
For i = LBound(uniqueArr) to UBound(uniqueArr)
' First, count how many measurements were taken today.
phCount = 0
For j = LBound(pHData) to UBound(pHData)
If phData(j).Dy== uniqueArr(i)
phCount = phCount + 1
Else
' This measurement was not taken on this date.
' Do nothing.
End If
Next j
' Now resize the temp array and store today's measurements in it.
ReDim todaysValues(1 To phCount)
phCount = 0
For j = LBound(pHData) to UBound(pHData)
If phData(j).Dy== uniqueArr(i)
phCount = phCount + 1
todaysValues(phCount) = phData(j).pH
Else
' This measurement was not taken on this date.
' Do nothing.
End If
Next j
' Here goes some code to calculate statistics (min, max, etc.)
Next i