I'm not sure if i should even post this, but here it is. What i need to do is calculate freeze-thaw cycles based on some data. What that means (for those that dont know) is that i have temperature data in an array. I need to know how many times the data goes below and comes back above a certain threshold, usually 0. This is a VB6 function that is supposed to do that. Please point out any obvious mistakes i might have made (btw it doesnt work right now).VB Code:
Function FreezeThaw(ByRef iData() As Single, Threshold As Single) As Long Dim iMax As Long Dim i As Long Dim Cycles As Long Dim LastNum As Long Dim Num As Single Dim Num2 As Single iMax = UBound(iData) - 1 For i = 0 To iMax Num = iData(i) Num2 = iData(i + 1) 'Make Sgn of num1 If Num > Threshold Then Num = 1 LastNum = 1 ElseIf Num < Threshold Then Num = -1 LastNum = 2 ElseIf Num = Threshold Then Num = LastNum End If 'Make sgn of num2 If Num2 > Threshold Then Num2 = 1 ElseIf Num2 < Threshold Then Num2 = -1 ElseIf Num2 = Threshold Then Num2 = Num End If If Num * Num2 = -1 Then Cycles = Cycles + 1 Next FreezeThaw = Int(Cycles / 2) End Function
It works by making any number above the threshold a 1, and any number below the threshold a -1, and any number equal to the threshold the value of the last number. Then it multlplies one number by the next one. So if both are less than the threshold then the product is 1. If both are above then it is also 1. However, if one number is above and one below, the answer is -1 and i know there has been a crossing. Sorry 4 the long post. Thanks in avance.
-Nishant
