问题
I am making a GUI based application (forms), and encountered the following error.
Firstly, I am declaring the following stuff in a module
Module test_mod
Public Structure sub_struct
Public test_int() As Integer
Public Sub foo()
ReDim test_int(3)
End Sub
End Structure
Public Structure main_struct
Public test_aaa As sub_struct
End Structure
End Module
Of course, my real code is longer and more complicated than this, but this piece of code will be a perfect example.
Then I declare this test_mod in the main class
Public Class Form1
Public test_this_struct As New test_mod.main_struct
'do something here
End class
My intention is making the test_this_struct accessible by other modules (which are not shown here), such that the main class will be short and tidy. However, it keeps complaining the following:
test_this_struct cannot expose type test_mod.main_structoutside the project through class form1.
I do not see any Private here, and I tired to remove the new, redim, and "struct in struct", but they did not work.
I found an article and its related content on MSDN, but it did not really help me.
回答1:
Try this:
Public Module test_mod
Public Structure sub_struct
Public test_int() As Integer
Public Sub foo()
ReDim test_int(3)
End Sub
End Structure
Public Structure main_struct
Public test_aaa As sub_struct
End Structure
End Module
Source: http://msdn.microsoft.com/en-us/library/aaxss7da.aspx
回答2:
By default modules and classes are Friend (only visible to your assembly).
Your form, however, is explicitly Public, which exposes it and its members to the world - which extends test_mod.main_struct's visibility.
Declare your module as Public too.
来源:https://stackoverflow.com/questions/26898462/cannot-declare-a-variable-with-public-access-in-a-class-from-a-module