Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Dependencies: none
- 'Note that all parameters are passed by reference. They _will be changed_.
- Sub Interchanger(RT1 As Double, RT2 As Double, RP1 As Double, RP2 As Double, _
- RG1 As Double, RG2 As Double, RG3 As Double, RG4 As Double, RE2 As Double, _
- RT5 As Double, RT6 As Double, RT8 As Double, RT9 As Double, RTE As Double, _
- hasError As Boolean)
- 'Transfer interchanger. This is going to be kind of messy.
- Dim T1, T2, P1, P2, G1, G2, G3, G4, E2, T5, T6, T8, T9, TE As Double
- Dim del, delta, T9C As Double
- Dim iDelp5 As Integer 'Fix(del + 0.5) is this now
- Dim iter As Integer
- Dim skipToggle As Boolean
- skipToggle = False
- T1 = RT1
- T2 = RT2
- P1 = RP1
- P2 = RP2
- G1 = RG1
- G2 = RG2
- G3 = RG3
- G4 = RG4
- E2 = RE2
- T5 = RT5
- T6 = RT6
- T8 = RT8
- 'T9 = RT9 In original code, but does nothing. Left for ~posterity~
- TE = RTE
- T9 = T2
- iter = 0
- Do
- iter = iter + 1
- T5 = (T9 * (P2 + G4) - T2 * T2) / G3
- T6 = (T1 * E2 * G1 + T9 * (P1 + G3) * (1# - E2)) / (P1 + G3 - G4 * E2)
- T8 = (T1 * G1 + T6 * G4) / (P1 + G3)
- 'Escape the loop and skip the piece right afterwards (goto 3)
- If (T8 < T1) Then
- skipToggle = True
- Exit Do
- End If
- T9C = (T5 * G3 + T6 * G4 - T8 * G3) / G4
- delta = Abs(T9 - T9C)
- del = 10000# * delta
- iDelp5 = del + 0.5
- 'Maybe escape the loop and goto 2
- If (iDelp5 <= 1) Then Exit Do
- If (iDelp5 > 100) Then
- T9 = T9 + 0.05 * (T9 - T9C)
- ElseIf (iDelp5 > 10) Then
- T9 = T9 + 0.03 * (T9 - T9C)
- ElseIf (iDelp5 > 5) Then
- T9 = T9 + 0.01 * (T9 - T9C)
- ElseIf (iDelp5 > 2) Then
- T9 = T9 + 0.005 * (T9 - T9C)
- Else 'If (iDelp5 > 1)
- T9 = T9 + 0.002 * (T9 - T9C)
- End If
- Loop
- 'The first segment after the loop, i.e., 2. Skip this if it was the first
- 'exit option from the loop.
- If (skipToggle = False) Then
- TE = (T9 - T6) / (T9 - T8)
- hasError = False
- 'The second segment after the loop, i.e., 3. This is the bad outcome.
- Else
- hasError = True
- End If
- 'This gets executed in both outcomes before the return.
- RT1 = T1
- RT2 = T2
- RP1 = P1
- RP2 = P2
- RG1 = G1
- RG2 = G2
- RG3 = G3
- RG4 = G4
- RE2 = E2
- RT5 = T5
- RT6 = T6
- RT8 = T8
- RT9 = T9
- RTE = TE
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement