vb模块数据是否可以在模块内写入,但对其他模块是公共和只读的?



有没有办法声明模块中的数据结构可以由模块中的任何函数写入,但从不同模块中的函数是只读的?

也许这就像C++让一个类返回到另一个类一样,只读(const(指针1st类的内部数据结构。

你需要的是一个可以从程序中的任何位置访问的公共属性(只读(和一个只有模块本身内部范围的私有字段。这是一个例子

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

此外,如果你想做一个也可以读写的公共属性,那么使用

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

这很简单!
您可以使用公共属性私有字段

  • 使用外部模块(或类等(的公共属性
  • 用于使用内部的私人字段。

感谢没有人

最新更新