Results 1 to 12 of 12

Thread: PLease HELP ME!! AAAARG

  1. #1

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375

    Question 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:
    1. Function FreezeThaw(ByRef iData() As Single, Threshold As Single) As Long
    2. Dim iMax As Long
    3. Dim i As Long
    4. Dim Cycles As Long
    5. Dim LastNum As Long
    6. Dim Num As Single
    7. Dim Num2 As Single
    8.  
    9. iMax = UBound(iData) - 1
    10. For i = 0 To iMax
    11.     Num = iData(i)
    12.     Num2 = iData(i + 1)
    13.    
    14.     'Make Sgn of num1
    15.     If Num > Threshold Then
    16.         Num = 1
    17.         LastNum = 1
    18.     ElseIf Num < Threshold Then
    19.         Num = -1
    20.         LastNum = 2
    21.     ElseIf Num = Threshold Then
    22.         Num = LastNum
    23.     End If
    24.    
    25.     'Make sgn of num2
    26.     If Num2 > Threshold Then
    27.         Num2 = 1
    28.     ElseIf Num2 < Threshold Then
    29.         Num2 = -1
    30.     ElseIf Num2 = Threshold Then
    31.         Num2 = Num
    32.     End If
    33.    
    34.     If Num * Num2 = -1 Then Cycles = Cycles + 1
    35. Next
    36. FreezeThaw = Int(Cycles / 2)
    37. 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.

  2. #2

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    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.

  3. #3

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Doesnt anyone have anything to say??!?!?!?!?
    You just proved that sig advertisements work.

  4. #4

  5. #5

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    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.

  6. #6

  7. #7
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Hmm,
    I just tested with this:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Arg(10) As Single
    3. List1.Clear
    4. For i = 0 To 10
    5.     Select Case i Mod 2
    6.         Case 0
    7.             Arg(i) = 4
    8.         Case 1
    9.             Arg(i) = 44
    10.     End Select
    11. Debug.Print "Element "; i; " = "; Arg(i)
    12. Next i
    13. Debug.Print "Num Cycles = "; FreezeThaw(Arg, 10)
    14. 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

  8. #8
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    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:
    1. Open InputFile For Input As 2
    2.     Open OutputFile For Output As 1
    3.     '''Open "c:\a.trt" For Output As #3
    4.     For i = 0 To UBound(ColList)
    5.         '''Print #3, "At " & i
    6.         Do While Not EOF(2)
    7.             Line Input #2, TempStr
    8.             TempArr = Split(TempStr, vbTab, -1, vbTextCompare)
    9.             ReDim Preserve iRecData(Count)
    10.             iRecData(Count) = TempArr(ColList(i))
    11.             'Debug.Print ColList(i), Count, iRecData(Count)
    12.             Count = Count + 1
    13.             '''Print #3, i & " :: " & iRecData(Count - 1)
    14.         Loop
    15.         '''Just so you know, we've reached EOF by know,
    16.         '''So, when i goes to 1, the Do loop
    17.         '''won't be executed.
    18.         ''''''Is this what you intended?
    19.        
    20.     Ret = FreezeThaw(iRecData, -5)
    21.     Print #1, ColList(i) & vbTab & Ret
    22.     Next

    Can you explain how your inputting is supposed to work?

    -Lou

  9. #9

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    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.

  10. #10

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    K heres a patch for the cmd_run code.

    VB Code:
    1. Look down...
    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.

  11. #11

    Thread Starter
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    doubt!!!!! Really sorry. The patch creates another problem. Heres the real patch
    VB Code:
    1. Private Sub CmdRun_Click()
    2. Call Working
    3. MsgBox InputFile & vbCrLf & OutputFile
    4. If Len(InputFile) > 0 And Len(txtOutputFile) > 0 Then
    5.     lblFile = InputFile
    6.        
    7.     Dim iRecData() As Single
    8.     Dim TempArr() As String
    9.     Dim i As Long
    10.     Dim Ret As Long
    11.     Dim Count As Long
    12.     Dim TempStr As String
    13.     ColList = Split(txtColList, ",", -1, vbTextCompare)
    14.    
    15.     Open InputFile For Input As 2
    16.     Open OutputFile For Output As 1
    17.    
    18.     For i = 0 To UBound(ColList)
    19.         Do While Not EOF(2)
    20.             Line Input #2, TempStr
    21.             TempArr = Split(TempStr, vbTab, -1, vbTextCompare)
    22.             ReDim Preserve iRecData(Count)
    23.             iRecData(Count) = TempArr(ColList(i))
    24.             'Debug.Print ColList(i), Count, iRecData(Count)
    25.             Count = Count + 1
    26.         Loop
    27.     Ret = FreezeThaw(iRecData(), 0)
    28.     Count = 0
    29.     Seek 2, 1
    30.     Print #1, "F-T cycles in column "; ColList(i); " = " & vbTab & Ret
    31.     Next
    32. End If
    33. Close
    34. Call Finished
    35. End Sub
    sorry bout that.
    You just proved that sig advertisements work.

  12. #12
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    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:
    1. Col 4   Col 5
    2. 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
  •  



Click Here to Expand Forum to Full Width