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?
Ready to start learning the SolidWorks API? Sign up for FREE membership here.Keep up with new videos, macros, and training events by joining our mailing list:
dblVolume = (4 / 3) * intRadius ^ 3
should be
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)"
Sub main()
Debug.Print Evaluate(PI_EQN, True, True)
End Sub