Greetings cybotzu and welcome to vbaexpress
Okay, let us step through the lines likely to be executing:
Option ExplicitDim p As Long
You have one variable declared at module level. So this is the only variable that will retain its value between procedures.
Sub PROJECT()
Dim n As Integer, i As Integer, j As Integer
Dim y(100) As Integer, sum As Long, p As Long, sum2 As Long, a As Long
n = InputBox(" Please enter the total of values to evaluate (12)", "VALUE")
If n < 2 Then
MsgBox "Incorrect value, please enter a value that is higher than 2", vbCritical, "ERROR"
Call PROJECT
Else
i = 0
sum = 0
Call PROM
j = 0
sum2 = 0
Call EXP
a = Sqr(sum2 / (n - 1))
End If
End Sub
In the above, assuming we typed a number of 2 or greater, we end up calling PROM().
Sub PROM()
Dim i As Integer, n As Integer
Dim sum As Long, y(100) As Integer
If i <= n - 1 Then
y(i) = InputBox("Please enter a value", "Value")
sum = sum + y(i)
i = i + 1
Call PROM
Else
p = sum / n
End If
End Sub
In PROM(), 'i' has a value of 0, as does 'n'. This is because both are declared local to the procedure, and Integer/Long variables default to 0. So... we are really testing:
If
0 <= 0-1 Or simplified,
If 0 <= -1 which of course it will not be.
Hence, the
Else gets executed, and we have
p = sum / n, or that is,
p = 0 / 0. So you see, you end up with a divided by zero error.
Does that makes sense?
Mark