Can someone please explain the fault in this code? I am getting overflow error. First i thought this might be due to large input values of n1, n2 i am giving in (order 10000), even after decreasing the values of them to few hundred's i am getting this error.
Private Sub CommandButton1_Click()
Dim Ds1, Ds2, Ds3, Ds4, Ds5, n1, n2, n3, n4, n5, C, m, a0, w, D, N, i, Pi As Double
Pi = 3.14159265359
Ds1 = TextBox8.Text
n1 = TextBox10.Text
Ds2 = TextBox13.Text
n2 = TextBox14.Text
Ds3 = TextBox17.Text
n3 = TextBox18.Text
Ds4 = TextBox11.Text
n4 = TextBox12.Text
Ds5 = TextBox15.Text
n5 = TextBox16.Text
C = TextBox20.Text
m = TextBox19.Text
a0 = TextBox22.Text
w = TextBox21.Text`
D = Sqr(((n1 * (Ds1 ^ 2)) + (n2 * (Ds2 ^ 2)) + (n3 * (Ds3 ^ 2)) + (n4 * (Ds4 ^ 2)) + (n5 * (Ds5 ^ 2))) / (n1 + n2 + n3 + n4 + n5))
N = n1 + n2 + n3 + n4 + n5
ReDim af1(N) As Double
ReDim Y(N) As Double
af1(0) = a0
For i = 1 To N
Y(i) = 1.12 - (0.23 * (af1(i - 1) / w)) + (10.55 * ((af1(i - 1) / w) ^ 2)) - (21.72 * ((af1(i - 1) / w) ^ 3)) + (30.39 * ((af1(i - 1) / w) ^ 4))
af1(i) = af1(i - 1) + (C * (D ^ m) * (Pi ^ (m / 2)) * ((af1(i - 1)) ^ (m / 2)) * (Y(i) ^ m))
Next i
TextBox11.Text = af1(N)
End Sub
af1
andY
as arrays and you are usingRedim
instead. Change it toDim
and try again.Ds1
,Ds2
,Ds3
asDouble
orVariant
? if you meant all of them to beDouble
, you need Dim Ds1 As Double, Ds2 As Double, Ds3 As Double`, etc.