Variables intro

6 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.04
List Price:  €123.26
You save:  €35.22
£75.10
List Price:  £105.15
You save:  £30.04
CA$138.85
List Price:  CA$194.39
You save:  CA$55.54
A$156.01
List Price:  A$218.42
You save:  A$62.41
S$131.39
List Price:  S$183.96
You save:  S$52.56
HK$775.83
List Price:  HK$1,086.20
You save:  HK$310.36
CHF 82.80
List Price:  CHF 115.93
You save:  CHF 33.12
NOK kr1,043.63
List Price:  NOK kr1,461.13
You save:  NOK kr417.49
DKK kr656.84
List Price:  DKK kr919.60
You save:  DKK kr262.76
NZ$167.59
List Price:  NZ$234.64
You save:  NZ$67.04
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,148.30
List Price:  ৳17,008.11
You save:  ৳4,859.80
₹8,537.62
List Price:  ₹11,953.01
You save:  ₹3,415.39
RM437.35
List Price:  RM612.31
You save:  RM174.96
₦160,863.91
List Price:  ₦225,215.91
You save:  ₦64,352
₨28,092.19
List Price:  ₨39,330.19
You save:  ₨11,238
฿3,350.66
List Price:  ฿4,691.06
You save:  ฿1,340.39
₺3,841.79
List Price:  ₺5,378.66
You save:  ₺1,536.87
B$568.98
List Price:  B$796.59
You save:  B$227.61
R1,868.66
List Price:  R2,616.20
You save:  R747.54
Лв172.01
List Price:  Лв240.82
You save:  Лв68.81
₩143,821.94
List Price:  ₩201,356.47
You save:  ₩57,534.53
₪362.36
List Price:  ₪507.32
You save:  ₪144.96
₱5,623.93
List Price:  ₱7,873.73
You save:  ₱2,249.79
¥14,366.05
List Price:  ¥20,113.05
You save:  ¥5,746.99
MX$1,950.18
List Price:  MX$2,730.33
You save:  MX$780.15
QR364.06
List Price:  QR509.70
You save:  QR145.64
P1,378.20
List Price:  P1,929.54
You save:  P551.33
KSh12,898.71
List Price:  KSh18,058.71
You save:  KSh5,160
E£5,073.42
List Price:  E£7,102.99
You save:  E£2,029.57
ብር13,121.18
List Price:  ብር18,370.18
You save:  ብር5,249
Kz91,740.82
List Price:  Kz128,440.82
You save:  Kz36,700
CLP$93,485.65
List Price:  CLP$130,883.65
You save:  CLP$37,398
CN¥728.69
List Price:  CN¥1,020.20
You save:  CN¥291.50
RD$5,909.40
List Price:  RD$8,273.40
You save:  RD$2,364
DA13,237.77
List Price:  DA18,533.41
You save:  DA5,295.64
FJ$225.77
List Price:  FJ$316.09
You save:  FJ$90.31
Q770.06
List Price:  Q1,078.12
You save:  Q308.05
GY$20,918.55
List Price:  GY$29,286.80
You save:  GY$8,368.25
ISK kr12,783.72
List Price:  ISK kr17,897.72
You save:  ISK kr5,114
DH925.40
List Price:  DH1,295.60
You save:  DH370.20
L1,725.73
List Price:  L2,416.09
You save:  L690.36
ден5,409.84
List Price:  ден7,573.99
You save:  ден2,164.15
MOP$798.85
List Price:  MOP$1,118.43
You save:  MOP$319.57
N$1,886.91
List Price:  N$2,641.75
You save:  N$754.84
C$3,679.51
List Price:  C$5,151.46
You save:  C$1,471.95
रु13,656.03
List Price:  रु19,119
You save:  रु5,462.96
S/366.91
List Price:  S/513.69
You save:  S/146.78
K405.25
List Price:  K567.37
You save:  K162.12
SAR375.05
List Price:  SAR525.09
You save:  SAR150.03
ZK2,792.07
List Price:  ZK3,909.02
You save:  ZK1,116.94
L438.21
List Price:  L613.52
You save:  L175.30
Kč2,197.59
List Price:  Kč3,076.71
You save:  Kč879.12
Ft35,691.43
List Price:  Ft49,969.43
You save:  Ft14,278
SEK kr968.31
List Price:  SEK kr1,355.67
You save:  SEK kr387.36
ARS$116,356.84
List Price:  ARS$162,904.23
You save:  ARS$46,547.39
Bs690.91
List Price:  Bs967.30
You save:  Bs276.39
COP$424,468.94
List Price:  COP$594,273.50
You save:  COP$169,804.55
₡50,609.75
List Price:  ₡70,855.68
You save:  ₡20,245.92
L2,579.74
List Price:  L3,611.74
You save:  L1,032
₲799,773.34
List Price:  ₲1,119,714.67
You save:  ₲319,941.33
$U4,185.15
List Price:  $U5,859.38
You save:  $U1,674.22
zł375.88
List Price:  zł526.25
You save:  zł150.37
Already have an account? Log In

Transcript

Hey guys, welcome back. So in this video we're going to speak about variables. So what is a variable, a variable is basically something that gets its value changed over and over again in your macro or in your procedure. Okay? So at some point in your procedure, it's value could be a one. So for example, let's say we would have a variable named x, the value of x at the beginning of the procedure or the macro, could be one.

And then during running the macro, it can become a two and then a three and then a five and then a seven. You know, its value can change over and over again, while you are running your macro. You can think about it as basically a bucket that you put a value inside, okay, and this value can change over and over again while running your macro. So why would that be useful or better? beneficial, like, why would I use variables, I'm gonna show you a simple problem. And we will use variables to solve that problem.

And you will basically discover how useful variables are. So basically, let's say we've got a rectangle, okay, we can recall from studying basic math in school that the area of a rectangle is equal to length, the length of the rectangle multiplied by the width, okay, and the perimeter is equal to two multiplied by the length plus the width. So add the length plus the width, and then multiply that by two to get the perimeter of a rectangle. So let's say I want to display the area of my rectangle here in cell B two, and I want to display the perimeter of my rectangle in cell C two under this header here named perimeter. in cell C one, so let's say that the length of my rectangle is equal to two, and the width is equal to three. Okay, so I can say range B two, so I want to display the area in cell B two, I can say range v two is equal to the length which is two, and then the width which is three, and I can also say to display my perimeter that the range c two is equal to the length is two and the width is three, so that's two by two plus three, okay, so that's two multiplied by two plus three, okay, so the area is going to be a six, and then the perimeter is going to be a 10.

So if you run this macro, you can see here that the area has been displayed in cell B two, it's six and the perimeter is 10 So let's say I want to calculate the area on the perimeter of a different rectangle, but this time, the length is four and the width is five. So what I need to do is to change here, the values of the length and the width, okay? So the length is four and the width is five. So I'm changing the values here of the length and the width. And if I run this macro, okay, you can see here, the area has become 20, and the perimeter has become 18. Okay, so let's say I want to calculate the area of the third rectangle, the different rectangle, the length is three, and the width is four, I will need to change the values here again, and change the lens to be a three and the width to be a four.

And then I would run my macro and get my results. So you see, every time I need to calculate the area of a difference. rectangle, I will need to change the values here in several locations. So I need to change it in the formula for calculating the area and I will need to change it also in the equation for calculating the perimeter. Okay, so this is not very efficient, right? Because I need to change it several times, so how about I can use a way to change it just one time, okay, so I can create a variable called l for length, and I can put it equal to two.

For example, let's say want to calculate the area and the perimeter for rectangle that has a length of two and the width of four so I can put this equal to two and width equals to four and it can also change it in the equation here. So I can make it L by W. And then also here two multiplied by l plus W. You can see here that now the equations are referencing the variables the length and the width. So whenever I need to change variables, I will need to change them in only one location or whenever I need to calculate the area of a different rectangle, I will need to insert the length and the width in only one location. So I'll need to do it here once only length equals to width equals four, if I run this macro, you can see here that the area is eight and the perimeter is 12.

Okay, so now I need to change it only once, let's say length is five with the six. Now if I run this macro, I can get the area and the perimeter here on the left. So you can see or you will need to only change it once. I don't have to change it several times. So imagine that you've got lots of sentences or lots of lines of code referencing your variables, you can just make only one change. And this change will be reflected in all the lines of code or all the sentences referencing these variables.

And that's a very simple example. You will see the power of variables They are much more powerful than that. But this is basically like a very simple use of variables why they would be useful this guy's was just a simple introduction to variables and we will go much deeper in the upcoming videos. Thank you very much for watching this video on please follow me on to the next video.

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.