Hi all,
I just figured I'd see if anyone here can help before I email my professor. I'm trying to follow the in-class example for the Excel based Visual Basic program I was given in class to try and figure out how to do the HW due next week.
The problem is the class example the professor gave that I copied won't compile. I double checked to make sure I followed what was typed, and as far as I can tell, it is correct. However, the problem lies in that when I click to compile, it says:
Compile Error:
Invalid outside procedure
The program is:
Module1 - 1
Function rhs(temp, ps)
rhs = 23.75 - 0.25 * temp + 0.75 * Sqr(ps)
End Function
Sub rk4(temp, ps, dt)
k1 = dt * rhs(temp, ps)
k2 = dt * rhs(temp + k1 / 2, ps)
k3 = dt * rhs(temp + k2 / 2, ps)
k4 = dt * rhs(temp + k3, ps)
temp = temp + (k1 + 2 * k2 + 2 * k3 + k4) / 6
End Sub
Sub main()
steps = [b5]
dt = [b6]
ps = [b8]
t = [a13]
[a13].Select
For i = 1 To steps
t = t + dt
Call rk4(temp, ps, dt)
templin = 110 + 0.3 * (ps - 25) * (1 - Exp(-t / 4))
ActiveCell.Offset(i, 0).Value = t
ActiveCell.Offset(i, 1).Value = temp
ActiveCell.Offset(i, 2).Value = templin
Next
End Sub
I have all the variables specified on the Excel worksheet. Can anyone see what I'm missing?
Thanks in advance.
I just figured I'd see if anyone here can help before I email my professor. I'm trying to follow the in-class example for the Excel based Visual Basic program I was given in class to try and figure out how to do the HW due next week.
The problem is the class example the professor gave that I copied won't compile. I double checked to make sure I followed what was typed, and as far as I can tell, it is correct. However, the problem lies in that when I click to compile, it says:
Compile Error:
Invalid outside procedure
The program is:
Module1 - 1
Function rhs(temp, ps)
rhs = 23.75 - 0.25 * temp + 0.75 * Sqr(ps)
End Function
Sub rk4(temp, ps, dt)
k1 = dt * rhs(temp, ps)
k2 = dt * rhs(temp + k1 / 2, ps)
k3 = dt * rhs(temp + k2 / 2, ps)
k4 = dt * rhs(temp + k3, ps)
temp = temp + (k1 + 2 * k2 + 2 * k3 + k4) / 6
End Sub
Sub main()
steps = [b5]
dt = [b6]
ps = [b8]
t = [a13]
[a13].Select
For i = 1 To steps
t = t + dt
Call rk4(temp, ps, dt)
templin = 110 + 0.3 * (ps - 25) * (1 - Exp(-t / 4))
ActiveCell.Offset(i, 0).Value = t
ActiveCell.Offset(i, 1).Value = temp
ActiveCell.Offset(i, 2).Value = templin
Next
End Sub
I have all the variables specified on the Excel worksheet. Can anyone see what I'm missing?
Thanks in advance.
Comment