Members of Modules

To wrap up our investigation of module types, do know that modules can have additional members beyond subroutines and functions. If you wish to define field data (as well as other members, such as properties or events), you are free to do so. For example, assume you wish to update MyModule to contain a single piece of public string data. Note that the GreetUser() method will now print out this value when invoked:

Module MyModule Public UserName As String

Sub GreetUser()

Console.WriteLine("Hello, {0}.", UserName) End Sub End Module

Like any module member, the UserName field can be directly accessed by any part of your application. For example:

Sub Main()

' Set user's name and call second form of GreetUser().

UserName = "Fred" MyModule.GreetUser()

End Sub

Source Code The FunWithModules project is located under the Chapter 3 subdirectory.

Was this article helpful?

0 0

Post a comment