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

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

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