Get a month of TabletWise Pro for free! Click here to redeem 
TabletWise.com
 

Variables intro

6 minutes
Share the link to this page
Copied
  Completed
You need to purchase the class to view this lesson.
One-time Purchase
$99.99
List Price:  $139.99
You save:  $40
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
A$143.72
List Price:  A$201.22
You save:  A$57.49
৳8,478.05
List Price:  ৳11,869.61
You save:  ৳3,391.56
CA$135.74
List Price:  CA$190.04
You save:  CA$54.30
CHF 94.02
List Price:  CHF 131.63
You save:  CHF 37.61
kr659.62
List Price:  kr923.50
You save:  kr263.87
€88.56
List Price:  €123.98
You save:  €35.42
£79.29
List Price:  £111.01
You save:  £31.72
HK$774.93
List Price:  HK$1,084.93
You save:  HK$310
₹7,514.60
List Price:  ₹10,520.75
You save:  ₹3,006.14
RM426.20
List Price:  RM596.70
You save:  RM170.50
₦38,796.12
List Price:  ₦54,316.12
You save:  ₦15,520
kr945.66
List Price:  kr1,323.96
You save:  kr378.30
NZ$152.40
List Price:  NZ$213.36
You save:  NZ$60.96
₱4,945.12
List Price:  ₱6,923.37
You save:  ₱1,978.24
₨16,688.33
List Price:  ₨23,364.33
You save:  ₨6,676
S$139.26
List Price:  S$194.97
You save:  S$55.71
฿3,126.68
List Price:  ฿4,377.48
You save:  ฿1,250.80
₺686.39
List Price:  ₺960.98
You save:  ₺274.58
R1,687.27
List Price:  R2,362.25
You save:  R674.97
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