0

Is there a way to declare that a data structure within a module can be written by any function within the module, but is read-only from a function in a different module?

Maybe this would be like in C++ having a class return to another class a read-only (const) pointer 1st class' its internal data structure.

Doug Null
  • 7,989
  • 15
  • 69
  • 148
  • Possible duplicate of [Auto Property with public getter and private setter](https://stackoverflow.com/questions/14085180/auto-property-with-public-getter-and-private-setter) – Rufus L Aug 17 '17 at 16:34

2 Answers2

2

What you need is a Public Property(read only) which can be accessed from anywhere in the program and a Private Field which only has the scope inside the module itself. Here is an example

Module myModule

   Private something As String 'This here is a Field

   'Below is the code for a read-only property
   Public Property SomethingWhichIsReadOnly As String
     'SomethingWhichIsReadOnly can be used from anywhere
     Get
        Return something         
     End Get
   End Property

   Public Function SomeFunction(ByVal value as Integer) As Boolean
      ...
      'You can use "something"(String Field declared above) in functions
      'Which can be accessed and modified only from the module itself
   End Function

End Module

Further if you want to make a Public Property which can be read and written as well, then use

Public Property SomethingWhichIsReadOnly As String
  Get
      Return something 
  End Get
  Private Set(ByVal value As String)
      something = value 'Setting the value to the Private Field
  End Set
End Property
Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
  • You can change the syntax highlighting of your code blocks to VB.NET (or any other language for that matter) by inserting `` before your code block. You can also write `` to change the language of _**all**_ code blocks in your post. -- For more information see the [Markdown and Formatting help](https://stackoverflow.com/help/formatting) under _**"Syntax highlighting for code"**_. – Visual Vincent Aug 20 '17 at 08:29
  • Thanks for the edit and also the info. Point duly noted. – boop_the_snoot Aug 20 '17 at 08:31
0

It's very Simple!
You can Use a Public Property and a Private Field.

  • Public Property for using Outer the Module (or Class or etc )
  • Private Field for using Inside it.

Thanks to nobody

PurTahan
  • 789
  • 8
  • 24