Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '------------------------------------------------------------------------------------------
- ' Notice of My Copyright and Intellectual Property Rights
- '
- ' Any intellectual property contained within the program by Joseph L. Bolen remains the
- ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
- ' publish or provide such intellectual property to any other person or entity for any
- ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
- '
- ' Copyright © 2014. All rights reserved.
- ' All trademarks remain the property of their respective owners.
- '-------------------------------------------------------------------------------------------
- ' Program Name: Module Demo
- ' Author: Joseph L. Bolen
- ' Date Created: Oct 2014
- '
- ' Description: Demonstration of the use of a Module for publicly accessed shared methods
- ' and variables.
- '
- ' Documentation is at:
- ' App's screen image is at: http://imgur.com/4xd73rA
- ' App's Visual Basic .NET code is at http://pastebin.com/vHfvzAjB
- ' Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
- '
- '-------------------------------------------------------------------------------------------
- Option Strict On
- Public Class MainForm
- #Region " Form Events"
- Private Sub MainForm_Load(sender As Object, e As EventArgs) _
- Handles MyBase.Load
- 'FriendValueLabel.Text = GlobalMethods.globalFriendVar
- FriendValueLabel.Text = globalFriendVar
- PublicValueLabel.Text = globalPublicVar
- End Sub
- #End Region
- #Region " Control Events"
- ' Process and calculate the sum of two numbers.
- Private Sub SumButton_Click(sender As Object, e As EventArgs) _
- Handles SumButton.Click
- Dim firstValue As Double = CDbl(FirstTextBox.Text)
- Dim secondtValue As Double = CDbl(SecondTextBox.Text)
- 'SumValueLabel.Text = PlainAddFunction(firstValue, secondtValue).ToString
- 'SumValueLabel.Text = FriendAddFunction(firstValue, secondtValue).ToString
- SumValueLabel.Text = PublicAddFunction(firstValue, secondtValue).ToString
- End Sub
- #End Region
- End Class
- '====================================================================================
- ' Module GlobalMethods
- '====================================================================================
- Module GlobalMethods
- #Region " Global Variables"
- ' globalPrivateVar is not accessible to other classes
- Private globalPrivateVar As String = "Private"
- ' globalFriendVar is accessible to other classes
- Friend globalFriendVar As String = "Friend"
- ' globalPublicVar is accessible to other classes.
- Public globalPublicVar As String = "Public"
- #End Region
- #Region " Global Methods"
- ' While not declared as such, this is a Public function.
- Function PlainAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
- Return value1 + value2
- End Function
- ' Explicitly declared Private function, is not accessible outside Module.
- Private Function PrivateAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
- Return value1 + value2
- End Function
- ' Explicitly declared Friend function.
- Friend Function FriendAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
- Return value1 + value2
- End Function
- ' Explicitly declared Public function.
- Public Function PublicAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
- Return value1 + value2
- End Function
- #End Region
- End Module
Advertisement
Add Comment
Please, Sign In to add comment