我具有模块级别的全局变量,并且具有以下COM接口类型。
Imports System.IO
Imports simpackcomslvLib
Imports simpackcompostLib
Module Globals
Public Srv As SpckCOMApp
Public Mdl As IScrModel
Public Post As PostComApp
Public Res As PostComProject
End Module
在另一个类中,我的某些过程更改了它们的对象值。我想运行一些过程,这些过程会在例如Mdl值更改时在工具的GUI上进行一些更改。
我尝试了以下方法,该方法为整数类型参数创建了一个对象,但由于对象(我的类型属于COM接口,所以我没有成功)。
Public Class myVar
Private mValue As Integer
Public Event VariableChanged(ByVal mvalue As Integer)
Public Property Variable() As Integer
Get
Variable = mValue
End Get
Set(ByVal value As Integer)
mValue = value
RaiseEvent VariableChanged(mValue)
End Set
End Property
End Class
在示例中使用上述代码
Public Class Form1
Private WithEvents test As New myVar
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
test.Variable = CInt(TextBox1.Text)
End Sub
Private Sub VariableChanged(ByVal NewValue As Integer) Handles test.VariableChanged
MessageBox.Show(NewValue)
End Sub
End Class
反正有没有在模块中实现我下面的变量,这样在模块级别使用的方式也是错误的,我应该将它们移到类下吗?
Module Globals
Public Srv As SpckCOMApp
Public Mdl As IScrModel
Public Post As PostComApp
Public Res As PostComProject
End Module