JayBeeOH

Module Demo

Oct 4th, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.71 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2014. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Module Demo
  13. ' Author:         Joseph L. Bolen
  14. ' Date Created:   Oct 2014
  15. '
  16. ' Description:    Demonstration of the use of a Module for publicly accessed shared methods
  17. '                 and variables.
  18. '
  19. '                 Documentation is at:
  20. '                   App's screen image is at: http://imgur.com/4xd73rA
  21. '                   App's Visual Basic .NET code is at http://pastebin.com/vHfvzAjB
  22. '                   Video tutorial at YouTube: http://www.youtube.com/user/bolenpresents
  23. '
  24. '-------------------------------------------------------------------------------------------
  25.  
  26. Option Strict On
  27.  
  28. Public Class MainForm
  29.  
  30. #Region " Form Events"
  31.  
  32.     Private Sub MainForm_Load(sender As Object, e As EventArgs) _
  33.         Handles MyBase.Load
  34.  
  35.         'FriendValueLabel.Text = GlobalMethods.globalFriendVar
  36.         FriendValueLabel.Text = globalFriendVar
  37.         PublicValueLabel.Text = globalPublicVar
  38.     End Sub
  39.  
  40. #End Region
  41.  
  42. #Region " Control Events"
  43.  
  44.     ' Process and calculate the sum of two numbers.
  45.     Private Sub SumButton_Click(sender As Object, e As EventArgs) _
  46.         Handles SumButton.Click
  47.  
  48.         Dim firstValue As Double = CDbl(FirstTextBox.Text)
  49.         Dim secondtValue As Double = CDbl(SecondTextBox.Text)
  50.  
  51.         'SumValueLabel.Text = PlainAddFunction(firstValue, secondtValue).ToString
  52.         'SumValueLabel.Text = FriendAddFunction(firstValue, secondtValue).ToString
  53.         SumValueLabel.Text = PublicAddFunction(firstValue, secondtValue).ToString
  54.     End Sub
  55.  
  56. #End Region
  57.  
  58. End Class
  59.  
  60. '====================================================================================
  61. ' Module GlobalMethods
  62. '====================================================================================
  63. Module GlobalMethods
  64.  
  65. #Region " Global Variables"
  66.  
  67.     ' globalPrivateVar is not accessible to other classes
  68.     Private globalPrivateVar As String = "Private"
  69.  
  70.     ' globalFriendVar is accessible to other classes
  71.     Friend globalFriendVar As String = "Friend"
  72.  
  73.     ' globalPublicVar is accessible to other classes.
  74.     Public globalPublicVar As String = "Public"
  75.  
  76. #End Region
  77.  
  78. #Region " Global Methods"
  79.  
  80.     ' While not declared as such, this is a Public function.
  81.     Function PlainAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
  82.         Return value1 + value2
  83.     End Function
  84.  
  85.     ' Explicitly declared Private function, is not accessible outside Module.
  86.     Private Function PrivateAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
  87.         Return value1 + value2
  88.     End Function
  89.  
  90.     ' Explicitly declared Friend function.
  91.     Friend Function FriendAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
  92.         Return value1 + value2
  93.     End Function
  94.  
  95.     ' Explicitly declared Public function.
  96.     Public Function PublicAddFunction(ByVal value1 As Double, ByVal value2 As Double) As Double
  97.         Return value1 + value2
  98.     End Function
  99.  
  100. #End Region
  101.  
  102. End Module
Advertisement
Add Comment
Please, Sign In to add comment