我是VBA的新手,希望获得一些有关运行代码时遇到的溢出错误的反馈。我已将所有变量声明为Double(因为我要处理大量数字),每个Sub代表一组不同的方程式,用于解决我要解决的问题。然后使用“ Range.value”命令将这些值打印在excel工作表中。代码的概念非常简单-基本上是从电子表格中插入值并计算输出。任何帮助将不胜感激。
Option Explicit
Dim T, m, d, xb, bh, bd, bm, Th, Tv, phi, L, B, bdr, w, s, a, Pi, h, X1, X2 As Double
Sub Thoriz(T, w, d, Th)
'To calculate the horizontal force on the anchor
Th = T - (w * d)
End Sub
Sub Angle(Th, T, phi, X1)
'To calculate the angle of catenary at connection
X1 = Th / T
phi = Atn(-X1 / Sqr(-X1 * X1 + 1)) + 2 * Atn(1)
End Sub
Sub Tvert(T, phi, s, w, Tv)
'To calculate the total line length
Tv = T * Sin(phi)
s = Tv / w
End Sub
Sub spreadlength1(a, s, d, h, X2)
'To calculate the total spread length
a = ((s ^ 2) - (d ^ 2)) / (2 * d)
X2 = 1 + d / a
h = a * ((Exp(X2) + Exp(–X2)) / 2)
End Sub
Sub spreadlength(B, xb, h)
'Spread length
B = 2 * (xb + h)
End Sub
Sub Caculations()
'INPUTTING OF VALUES
T = Range("D3").Value
m = Range("D4").Value
d = Range("D5").Value
xb = Range("D6").Value
bh = Range("D7").Value
bd = Range("D8").Value
bm = Range("D9").Value
'CALCULATIONS
'Calculating the Horizontal force on the anchor
Call Thoriz(T, w, d, Th)
'Calculating the angle of catenary at the connection
Pi = 3.1415926536 'Defining the value of Pi
phi = phi * 180 / (Pi) 'Conversion of rad to deg
Call Angle(Th, T, phi, X1)
'Calculating the total line length
Call Tvert(T, phi, s, w, Tv)
'Calculating the spread length
Call spreadlength1(a, s, d, h, X2)
Call spreadlength(B, xb, h)
'OUTPUTTING OF VALUES
Range("D13").Value = Th
Range("D14").Value = phi
Range("D15").Value = L
Range("D16").Value = B
Range("D17").Value = bdr
End Sub