11. VbScript | Subroutines

Today we are going to talk about Subroutines in VbScript. Subroutines are used to store a bunch of codes inside a document and recall it to use it whenever you want. …

Subroutines store scripts inside the “sub” tag; like this:

If you run a file with only subroutines, nothing will happen. You need to call the subroutine to run what is inside the subroutine. Like this:

Output:

1

Also, the order of the subroutine and when you call it does not matter. Like this:

You can also change what is inside of the subroutine without directly changing the code. You can do this by setting a variable inside of the subroutine as x. And change the value of x as you like. For example:

Output:

2

Expanding upon the usage of variables, you can use more than 1 variable to change what is inside the subroutine. Like so:

Output:

3


Example1:

Output:

4

Example2:

Output:

4


What's Your Opinion?