Lesson 4 of 18

Variables that Contain Variables

Duration: 2:54 Watch on YouTube (external link, opens in new tab)

Markdown version

In this lesson

Roy Osherove avoids repeating the same path by creating a full path generation directory variable whose default value is made up of two other variables. He makes it a macro, so that it expands the variable references inside it every time it is used, which gives a hierarchy of variables.

Transcript

345 words

[00:03] (external link, opens in new tab) Next, let's take a look at more interesting types of variables. In this case, what I want to see is this interesting issue in that I have some path that always keeps repeating at least twice. For example, I don't want to repeat myself with with the location of a new file txt. So, what I can do is I can say, you know what, I have this path that is always true. And that is everything here. I can also say you know what the path of new file txt is this.

[00:35] (external link, opens in new tab) So I can choose for example to take all this, cut it and say new file path. However, if I ever want to write multiple files, maybe I don't want to do that. Maybe instead what I'm going to do is I'm going to say

[01:06] (external link, opens in new tab) Let's take these two and make it full sorry full path generation directory like this. If I press F3, I can make this directory variable. I can make it a macro and I can make the default value to be made up of these two variables.

[01:40] (external link, opens in new tab) Maybe I'll remove the last slash. So now I have this variable that's made out of two subvariables and it's I have to make it a macro. So every time I use it, it actually expands the variable references inside it. So now if I try now I only have a single variable and it still contains the right stuff. So now I can use that variable here and I can replace this long line with

[02:10] (external link, opens in new tab) Full path generation. So I can have this hierarchy. And if I look in the project tab here under variables, if I save it, hopefully it refreshes. It has a bug where let's see if I can refresh it from here. Okay, so now I can see that I have these variables here and they're made up of each other. Now,

[02:42] (external link, opens in new tab) Now I can more easily move on to let's say adding stuff to multiple files or looping over files in the next few videos.