Invoking Methods

To invoke a method you simply call its name. Continuing with the preceding example, you can invoke the DoSomething method by simply typing the following line:

DoSomething()

If the method is a Function, you should assign the invocation to a variable as follows:

Dim targetOfInvocation As Boolean = DoSomethingElse()

This is important if you need to evaluate the value returned by the method. If you do not need to evaluate the result, you can simply invoke Function as if it were Sub:

'Allowed DoSomethingElse()

You can basically invoke functions anywhere you need a value. Continuing with the preceding example, the following code is acceptable:

Console.WriteLine(DoSomethingElse())

In the preceding examples, we act as if the method were ...

Get Visual Basic® 2010 Unleashed 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.