O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Subroutines

As you have seen, a subroutine is a language construct that allows you to split a large task into smaller pieces. In the previous example, you implemented a subroutine that does the same thing every time it is called: outputs the same string to the console, and then waits until the user presses Enter. This case is rarely useful. There are many cases when you would like the subroutine to do the same operation, but on different data. In this example, we would like to output a different string when the user has entered an incorrect value and the program will terminate abnormally, and a success message when the task of summing the array elements is successful. This is achievable through the use of subroutines with arguments, as illustrated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required