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 ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.