 Hey everybody, this is Brian, and this is video 18. Today we're going to be discussing subroutines. What is a subroutine? Well, you've seen them all along. See sub main and sub, that's a subroutine. It's just a block of code. So let's actually make one. Let's say sub print message as string. That's a subroutine. So notice how it says sub with in sub. A subroutine does not return a value. However, you can pass values to it. See, there is our parameter list. You can have multiple parameters. For example, you can say name as string. So you can have multiple parameters or none at all. In this case, we're just going to say message and name. And in here, we'll just use the console.write line, something we're very familiar with. We'll say from and name message equals. And we will just say message. So all this is going to do is it's going to print these out. And it's going to say from name, message equals, message. Notice how you can put these and use them in any order you want. It doesn't really matter. Now how do you use a subroutine? Very simple. You say print. Now you notice how I hit parentheses. You really don't need to do that in Visual Basic. You can just say message. So we'll say hello. And then comma will jump to your next parameter. And we will say this is from Bob, Bob saying hello. Notice how it automatically adds that in. If you're coming from an old version of Visual Basic, this would have generated an error. We will get into functions later, but that would be a function. But for the new version, dot none, what you're using now, you have to encapsulate this in parentheses. Don't worry if you forget. It'll do it automatically. Let's run this. Uh-oh, build errors. What did we do? Yes, expected. We missed something. Yes, we did. Let's run this again. From Bob, message equal, hello. Now, why do you need a subroutine? Hmm. Well, what if you want to do that over and over and over again? We use the Mary Chad group that we're used to. This is what subroutines can do for you. Message from Bob, hello. Message from Mary, hi. Message from Chad, hola. So what we're doing is we're saying print, and it's calling this subroutine down here, and executing the code inside of the subroutine. Once again, let's go back through this. We're calling print, and it's executing the code inside of print. You're passing it parameters. And there's our parameter list. Let's do another one. Just for clarity's sake. Let's call it sub, and it'll say counter. And give it a blank list here. Let's actually declare a variable above the main. I count as integer. We'll say counter equals 0. Down here, we'll say counter plus equal 1. And then console dot write line. Now let's explain a little bit of what we've done here. We've made a variable outside of main. And we're calling it down here in counter. This is called a global variable, meaning it's available to all the subroutines. If we put this in main, it's only going to be available in the main subroutine, and an error will be thrown when you try to access it down here. That's called variable scope. Very important you understand that concept. So I'm going to go over it real quick one more time. Because the variable is outside of any subroutine, it is a global variable, meaning it can be accessed by any subroutine. If you put it inside of a subroutine, it's only available to that specific subroutine. So if we put it in main, counter will not be able to access it. Now let's just call counter. And let's call counter a few times. Get rid of R. Then let's run this, see what happens. And you see the variable is incremented, 1, 2, 3. So by calling that subroutine, you can manipulate data in other scopes, in this case, in the global scope. So that is our tutorial on subroutines. I hope you found this video educational and entertaining. And thank you for watching.