Я хочу, чтобы мой код проходил через лист, ища точку, где есть положительное значение d, за которым следует отрицательное значение d, затем выполните следующее уравнение, которое является CCT.Оператор IF, встроенный внутри массива
Он не признает, что оператор IF фактически становится истинным на i=22
, и вместо этого будет проходить весь цикл и дать мне деление на нулевую ошибку.
Любая помощь приветствуется.
Sub CCT()
'Variable Declarations
Dim us As Double 'u coordinate of source
Dim vs As Double 'v coordinate of source
Dim u(100) As Double 'u coordinate of the isotemperature line
Dim v(100) As Double 'v coordinate of the isotemperature line
Dim d(100) As Double 'Distance between the source line and the isotemperature line
Dim t(100) As Double 'Slope of the isotemperature line
Dim tt(100) As Double 'Temperature
Dim i As Integer 'Counter
Dim d1 As Double 'dj
Dim d2 As Double 'dj+1
Dim tt1 As Double 'tj
Dim tt2 As Double 'tj+1
Dim CCT As Double 'CCT
'Reading in the Variables
us = Worksheets("CCTIsotemp").Cells(10, 12).Value
vs = Worksheets("CCTIsotemp").Cells(10, 13).Value
'Doing the Math
For i = 1 To 31
u(i) = Worksheets("CCTIsotemp").Cells(9 + i, 4).Value
v(i) = Worksheets("CCTIsotemp").Cells(9 + i, 5).Value
t(i) = Worksheets("CCTIsotemp").Cells(9 + i, 6).Value
tt(i) = Worksheets("CCTIsotemp").Cells(9 + i, 3).Value
d(i) = ((vs - v(i)) - t(i) * (us - u(i)))/(1 + t(i)^2)^1/2
If d(i) < 0 And d(i - 1) > 0 Then
d1 = d(i - 1)
d2 = d(i)
tt1 = t(i - 1)
tt2 = t(i)
End If
Next i
CCT = ((1/tt1) + (d1/(d1 - d2)) * ((1/tt2) - (1/tt1)))^(-1)
'write back
Worksheets("CCTIsotemp").Cells(10, 15) = CCT
Worksheets("CCTIsotemp").Cells(10, 16) = d1
Worksheets("CCTIsotemp").Cells(10, 17) = d2
Worksheets("CCTIsotemp").Cells(10, 18) = d(i)
Worksheets("CCTIsotemp").Cells(10, 19) = i
End Sub