Cannot declare a variable with public access in a class from a module

佐手、 提交于 2020-01-11 12:43:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!