In this video, we're going to speak about constants and constants are basically values or text that their value does not change. Like, for example, the PI value. The PI value is a long decimal, but it starts with three point 14 and then a lot of other digits. And for the sake of simplicity, we're just going to approximate it to three point 14. So this value is like constant. So you can actually declare a constant to be either a public so that it can be used from any Sub procedure in any module in your workbook or it can be declared as a private.
And in that case, it can be only used in the module that has been declared in. So to declare a constant, all you need to do is to write public to say we're gonna declare a public constant. So you're gonna write public const Let's say we're going to call it pi value as single, for example, so we're going to declare its status up to be a single equal to three point 14. Okay, so we're declaring a constant is going to be public. So it can be used in any Sub procedure. And in any module in our workbook, and its data type is going to be a single, and its value is going to be three point 14.
So this is how you can declare a constant. so the value of this constant can be used in any macro in our workbook. So in this case, if you run this macro, for example here, we're going to get the area of the circle and it's going to assume the value of the PI to be three point 14. So if I run through this macro actually step by step, you can see here, the PI value is three point 14. It got its value from This public constant, and we're able to get the value of our area, we could do that as well. For the second circle, you can see here that actually the pie value is recognized as three point 14, even before calculating the area is recognizing the constant that we have declared.
Okay, so this is how you can declare a constant. And this can work, of course, in any module. So if you, if you have actually another Sub procedure in Module Two, here, I've got another Sub procedure called circle three, you can calculate the area of that circle is going to recognize that this PI value is equal to three point 14. Also, you could make the constant private and in that case, actually, the value for it would be only recognized in module one. So if you run these macros in Module One, you're going to be able to get the area of the circle normally, however, if you go to Module Two, and since the constant has been declared to be private To only module one, if you run, actually, the macro in Module Two, if you step through that step by step using f8 on your keyboard is here, actually the PI value is empty, it's not recognizing the constant pi value because it's been declared as a private, okay?
We get the area's zero because it's empty is actually a zero, you're multiplying something by zero you get a zero. Okay, so, this is how you can declare either a public or private constant. You can also declare a constant to be specific to just a certain Sub procedure by declaring its value inside the Sub procedure by writing const and then the name of the constant as whatever data type you want to declare as to be equal to its value. Okay, so you can actually do that as well. You can make the value of the constant only specific to a particular Sub procedure. This is what we've done here in these two sub procedures.