Declaring Constants

4 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€88.24
List Price:  €123.54
You save:  €35.30
£75.24
List Price:  £105.34
You save:  £30.10
CA$138.27
List Price:  CA$193.58
You save:  CA$55.31
A$155.52
List Price:  A$217.74
You save:  A$62.21
S$129.72
List Price:  S$181.61
You save:  S$51.89
HK$774.96
List Price:  HK$1,084.98
You save:  HK$310.01
CHF 82.44
List Price:  CHF 115.42
You save:  CHF 32.98
NOK kr1,037.32
List Price:  NOK kr1,452.30
You save:  NOK kr414.97
DKK kr658.46
List Price:  DKK kr921.87
You save:  DKK kr263.41
NZ$168.37
List Price:  NZ$235.72
You save:  NZ$67.35
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,188.92
List Price:  ৳17,064.98
You save:  ৳4,876.05
₹8,445.28
List Price:  ₹11,823.73
You save:  ₹3,378.45
RM426.95
List Price:  RM597.75
You save:  RM170.80
₦160,531.94
List Price:  ₦224,751.14
You save:  ₦64,219.20
₨28,187.10
List Price:  ₨39,463.07
You save:  ₨11,275.97
฿3,305.66
List Price:  ฿4,628.06
You save:  ฿1,322.40
₺3,856.30
List Price:  ₺5,398.97
You save:  ₺1,542.67
B$572.79
List Price:  B$801.93
You save:  B$229.14
R1,839.94
List Price:  R2,576
You save:  R736.05
Лв172.54
List Price:  Лв241.56
You save:  Лв69.02
₩139,920.29
List Price:  ₩195,894.01
You save:  ₩55,973.71
₪360.84
List Price:  ₪505.20
You save:  ₪144.35
₱5,547.44
List Price:  ₱7,766.64
You save:  ₱2,219.20
¥14,467.90
List Price:  ¥20,255.64
You save:  ¥5,787.74
MX$1,966.85
List Price:  MX$2,753.67
You save:  MX$786.82
QR364.06
List Price:  QR509.70
You save:  QR145.64
P1,372.95
List Price:  P1,922.18
You save:  P549.23
KSh12,948.70
List Price:  KSh18,128.70
You save:  KSh5,180
E£5,078.29
List Price:  E£7,109.82
You save:  E£2,031.52
ብር13,459.34
List Price:  ብር18,843.61
You save:  ብር5,384.27
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$94,766.52
List Price:  CLP$132,676.92
You save:  CLP$37,910.40
CN¥729.42
List Price:  CN¥1,021.22
You save:  CN¥291.80
RD$5,902.61
List Price:  RD$8,263.89
You save:  RD$2,361.28
DA13,270.22
List Price:  DA18,578.84
You save:  DA5,308.62
FJ$225.66
List Price:  FJ$315.94
You save:  FJ$90.27
Q770.30
List Price:  Q1,078.46
You save:  Q308.15
GY$20,924.33
List Price:  GY$29,294.90
You save:  GY$8,370.57
ISK kr12,909.70
List Price:  ISK kr18,074.10
You save:  ISK kr5,164.40
DH926.13
List Price:  DH1,296.62
You save:  DH370.49
L1,723.23
List Price:  L2,412.59
You save:  L689.36
ден5,428.07
List Price:  ден7,599.52
You save:  ден2,171.44
MOP$801.19
List Price:  MOP$1,121.71
You save:  MOP$320.51
N$1,867.19
List Price:  N$2,614.14
You save:  N$746.95
C$3,690.56
List Price:  C$5,166.94
You save:  C$1,476.37
रु13,561.38
List Price:  रु18,986.48
You save:  रु5,425.09
S/367.72
List Price:  S/514.83
You save:  S/147.10
K409.48
List Price:  K573.29
You save:  K163.81
SAR374.98
List Price:  SAR524.99
You save:  SAR150
ZK2,790.70
List Price:  ZK3,907.09
You save:  ZK1,116.39
L439.28
List Price:  L615.01
You save:  L175.73
Kč2,197.68
List Price:  Kč3,076.83
You save:  Kč879.15
Ft35,673.38
List Price:  Ft49,944.16
You save:  Ft14,270.78
SEK kr966.64
List Price:  SEK kr1,353.33
You save:  SEK kr386.69
ARS$117,258.10
List Price:  ARS$164,166.03
You save:  ARS$46,907.93
Bs693.19
List Price:  Bs970.49
You save:  Bs277.30
COP$419,705.17
List Price:  COP$587,604.03
You save:  COP$167,898.85
₡50,658.12
List Price:  ₡70,923.39
You save:  ₡20,265.27
L2,602.65
List Price:  L3,643.81
You save:  L1,041.16
₲803,267.16
List Price:  ₲1,124,606.16
You save:  ₲321,338.99
$U4,195.69
List Price:  $U5,874.13
You save:  $U1,678.44
zł377.16
List Price:  zł528.05
You save:  zł150.88
Already have an account? Log In

Transcript

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.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.