C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Module2: This module has a field, _value, which is shared automatically (implicitly). So the field has only one instance.
Sub: In Module2 we see a Sub called Increment. This is by default "Friend." It can be easily accessed from Main.
Increment: When Increment is called, the field _value is changed. This change persists throughout uses of Increment.
Note: This demonstrates that the field is shared, even though it has no shared keyword.
SharedVB.NET program that uses modules
Module Module1
Sub Main()
' Use Module2.
' ... It does not need to be created.
Module2.Increment()
Module2.Increment()
Module2.Increment()
End Sub
End Module
Module Module2
Dim _value As Integer
Sub Increment()
' The value is shared.
Console.WriteLine(_value)
' Change the value.
_value += 1
End Sub
End Module
Output
0
1
2
Caution: If you try to create a Module, you will get an error. Please consider adding a class to fix this problem.
Error:
Module 'Module2' cannot be used as a type.