简体   繁体   English

公共类的呼叫子

[英]Calling Sub from Public Class

I've got this code: 我有以下代码:

  Public Class Events

        Inherits MyModule
        Private myTag As MyPoint
        'Call Calculations() here!


        Public Overrides Sub Calculations()
         'Do stuff with myTag
        End Sub
    End Class

As commented, I need to call Calculations() from class Events. 如前所述,我需要从事件类中调用Calculations()。 I tried Dim mycalc As New Calculations() but I get 我尝试了Dim mycalc As New Calculations()但我得到了

Type 'Calculations' is not defined.

When you do this: 执行此操作时:

Dim mycalc As New Calculations()

You're not trying to call the Calculations method. 您没有尝试调用Calculations方法。 You're trying to instantiate the Calculations class . 您正在尝试实例化Calculations It's not a class, hence the error. 这不是一个类,因此是错误。

You need to create an instance of the class and then call the method on that instance. 您需要创建该类的实例,然后在该实例上调用该方法。 Something like this: 像这样:

Dim myEvents As New Events()
myEvents.Calculations()

Conversely, if you're trying to call the method from within the Events class, you can just call it directly (since the current class instance is already defined): 相反,如果你想打电话从Events类,你可以把它直接(因为当前的类实例已经被定义):

Calculations()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM