locked
VB module RRS feed

  • Question

  • In http://msdn.microsoft.com/en-us/library/aaxss7da.aspx

    Access Level. Within a module, you can declare each member with its own access level. Module members default to Public (Visual Basic) access, except variables and constants, which default to Private (Visual Basic) access. When a module has more restricted access than one of its members, the specified module access level takes precedence.

    Can anyone please give me an example of a default private variable and constants declaration? (with no explicit access key words?)

    Tuesday, June 19, 2012 1:29 PM

Answers

  •    Const pi As Double = 3.14
       Dim var As Integer

    It's common practice to write the access modifier instead of "Dim", so there are no doubts.

    I don't use Modules at all because it automatically imports all members at project level, and that contradicts the concept of giving structure to a project's content.


    Armin

    • Proposed as answer by Paul P Clement IV Tuesday, June 19, 2012 1:56 PM
    • Marked as answer by Youen Zen Monday, July 2, 2012 8:02 AM
    Tuesday, June 19, 2012 1:42 PM

All replies

  •    Const pi As Double = 3.14
       Dim var As Integer

    It's common practice to write the access modifier instead of "Dim", so there are no doubts.

    I don't use Modules at all because it automatically imports all members at project level, and that contradicts the concept of giving structure to a project's content.


    Armin

    • Proposed as answer by Paul P Clement IV Tuesday, June 19, 2012 1:56 PM
    • Marked as answer by Youen Zen Monday, July 2, 2012 8:02 AM
    Tuesday, June 19, 2012 1:42 PM
  • In the declarations section of the module;

    'Const can only be accessed within the module...
    Private Const ModuleName As String ="MyModule"
    
    'Const can be accessed by other modules...
    Public Const ModuleVersion As String = "v1.0"
    
    'Variable can only be accessed within the module...
    Private msModuleName As String = "MyModule"
    
    'Variable can only be accessed by other modules...
    Public msModuleVersion As String = "v1.0"
    
    'Sub/Function can only be used by other procedures within the module...
    Private Sub MySub()
        .
        .
        .
    End Sub
    
    'Sub/Function can only be used by procedures in other modules...
    Public Sub MyOtherSub()
        .
        .
        .
    End Sub
    
    'Typically used to expose private variables to other modules...
    Public Property Get ModuleName() as string
        return msModulename
    End Property



    For the benefit of others, please mark posts as answered or helpful when they answer or assist you in finding the answer. "Don't confuse fame with success. Paris Hilton is one; Helen Keller is the other." - with apologies to Erma Bombeck for changing her words.

    Wednesday, June 20, 2012 6:09 AM