|
-
Aug 28th, 2001, 10:08 AM
#1
Thread Starter
Frenzied Member
PLease HELP ME!! AAAARG
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
Last edited by nishantp; Aug 28th, 2001 at 11:32 AM.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 10:44 AM
#2
Thread Starter
Frenzied Member
Come on. All im asking is that you look at it and say whether you see any mistakes.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 11:37 AM
#3
Thread Starter
Frenzied Member
Doesnt anyone have anything to say??!?!?!?!?
You just proved that sig advertisements work.
-
Aug 28th, 2001, 11:43 AM
#4
Just Came On, so I just saw your desperate plea.
Let me check it out, and I'll be right back.
-Lou
-
Aug 28th, 2001, 11:50 AM
#5
Thread Starter
Frenzied Member
Originally posted by NotLKH
Just Came On, so I just saw your desperate plea.
Let me check it out, and I'll be right back.
-Lou
thanks man
You just proved that sig advertisements work.
-
Aug 28th, 2001, 11:59 AM
#6
Couple of more minutes,
MY PC DIED!
Been doing that a bit lately...
-Lou
-
Aug 28th, 2001, 12:05 PM
#7
Hmm,
I just tested with this:
VB Code:
Private Sub Command1_Click()
Dim Arg(10) As Single
List1.Clear
For i = 0 To 10
Select Case i Mod 2
Case 0
Arg(i) = 4
Case 1
Arg(i) = 44
End Select
Debug.Print "Element "; i; " = "; Arg(i)
Next i
Debug.Print "Num Cycles = "; FreezeThaw(Arg, 10)
End Sub
And received:
Code:
Element 0 = 4
Element 1 = 44
Element 2 = 4
Element 3 = 44
Element 4 = 4
Element 5 = 44
Element 6 = 4
Element 7 = 44
Element 8 = 4
Element 9 = 44
Element 10 = 4
Num Cycles = 5
Which seems correct, for a threshold of 10.
So, it seems to work.
What happens for you?
-Lou
-
Aug 28th, 2001, 01:19 PM
#8
Well, so far:
I placed a comment in the code here you should check out:
As a result of your split on 4,5 from txtColList
i is supposed to go from 0 to 1.
But, when i = 1, you've already gotten to EOF(2)
so nothing happens beyond i = 0.
VB Code:
Open InputFile For Input As 2
Open OutputFile For Output As 1
'''Open "c:\a.trt" For Output As #3
For i = 0 To UBound(ColList)
'''Print #3, "At " & i
Do While Not EOF(2)
Line Input #2, TempStr
TempArr = Split(TempStr, vbTab, -1, vbTextCompare)
ReDim Preserve iRecData(Count)
iRecData(Count) = TempArr(ColList(i))
'Debug.Print ColList(i), Count, iRecData(Count)
Count = Count + 1
'''Print #3, i & " :: " & iRecData(Count - 1)
Loop
'''Just so you know, we've reached EOF by know,
'''So, when i goes to 1, the Do loop
'''won't be executed.
''''''Is this what you intended?
Ret = FreezeThaw(iRecData, -5)
Print #1, ColList(i) & vbTab & Ret
Next
Can you explain how your inputting is supposed to work?
-Lou
-
Aug 28th, 2001, 01:25 PM
#9
Thread Starter
Frenzied Member
Ahh! no thats not what i intended at all!! Thanks a lot for pointing that out!! Im writing a patch for that now...
You just proved that sig advertisements work.
-
Aug 28th, 2001, 01:38 PM
#10
Thread Starter
Frenzied Member
K heres a patch for the cmd_run code.
All ive done is added Seek 2,1 after the do loop to return to the start of the file. I know that going through the file twice isnt efficient, but i think i should worry about that after i get this working. Thanks again. Your suggestions will be appreciated.
Last edited by nishantp; Aug 28th, 2001 at 01:47 PM.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 01:45 PM
#11
Thread Starter
Frenzied Member
doubt!!!!! Really sorry. The patch creates another problem. Heres the real patch
VB Code:
Private Sub CmdRun_Click()
Call Working
MsgBox InputFile & vbCrLf & OutputFile
If Len(InputFile) > 0 And Len(txtOutputFile) > 0 Then
lblFile = InputFile
Dim iRecData() As Single
Dim TempArr() As String
Dim i As Long
Dim Ret As Long
Dim Count As Long
Dim TempStr As String
ColList = Split(txtColList, ",", -1, vbTextCompare)
Open InputFile For Input As 2
Open OutputFile For Output As 1
For i = 0 To UBound(ColList)
Do While Not EOF(2)
Line Input #2, TempStr
TempArr = Split(TempStr, vbTab, -1, vbTextCompare)
ReDim Preserve iRecData(Count)
iRecData(Count) = TempArr(ColList(i))
'Debug.Print ColList(i), Count, iRecData(Count)
Count = Count + 1
Loop
Ret = FreezeThaw(iRecData(), 0)
Count = 0
Seek 2, 1
Print #1, "F-T cycles in column "; ColList(i); " = " & vbTab & Ret
Next
End If
Close
Call Finished
End Sub
sorry bout that.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 02:23 PM
#12
Hmm,
Just ran it, on cols 4 and 5, and received:
Code:
F-T cycles in column 4 = 3
F-T cycles in column 5 = 3
AND, I just went thru them by hand, and it matches.
Actually, column 4 performs 3 complete loops,
while column 5 goes thru 3.5. {the last 2 values of col 5 are .011 and -.293
Isn't 3 & 3 the correct returns?
{ Just to confirm, this is how your program reads the columns,
using the first row to illustrate:
VB Code:
Col 4 Col 5
4 11.00 15.93 14.04 1.894 1.932
}
-Lou
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|