You are here: Home » Macro Library » Lesson 1.2 homework solution
dblVolume = (4 / 3) * intRadius ^ 3
dblVolume = (4 / 3) *dblPi* intRadius ^ 3
Oops. :) Thanks for pointing that out Joe!
I attempted to enter the more accurate version for pie with the declarative variables and use a constant command. The program didn’t enjoy my antics very much, so can I conclude that there are to be no formulas in the variable declaration sections? Even if the answer is a constant?
If your constant declaration contains any variables then VBA will throw a compile error. If you want pi controlled as a constant, your options are:
1. Create a constant with pi out to many digits, like this:
Const PI As Double = 3.14159265358979
2. Create a string constant containing 4 * Atn(1) (which will calculate the value of pi) and then evaluate it in your code, like this:
Const PI_EQN As String = "4 * Atn(1)"
Debug.Print Evaluate(PI_EQN, True, True)
You must be logged in to post a comment.