Functions

You have seen examples of Visual Basic built-in functions when you learned about conversion between different data types. We have used these functions in some of the examples you have seen since then. A function is a subroutine that returns a value. The syntax is slightly different but the functionality is identical. The difference is that it returns a value. Let's modify your last example to transform the Add subroutine into a function.

Module Module1

   Sub Main()
      Console.Out.WriteLine("Enter a value for i and press <Enter>:")
      Dim i As Integer
      i = CInt(Console.In.ReadLine())

      Console.Out.WriteLine("Enter a value for j and press <Enter>:")
      Dim j As Integer
      j = CInt(Console.In.ReadLine())
      Dim sum As Integer
      sum = Add(i, j) WaitForEnter("The ...

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.