0

I've global variables in module level with below COM-interface types.

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

In another classes some of my procedures change their object values. I'd like to run some of my procedures which made some changes on my tool's GUI when the for example Mdl value is changed.

I tried with below method which made for an integer type parameter but i didnt succeded for my case, i think because of their object(I types belongs to COM-interface.

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

Usage of above code in an example

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

Is there anyway to implement my below variables in a module such a way also using in module level is wrong should i move them under the class?

Module Globals
    Public Srv As SpckCOMApp
    Public Mdl As IScrModel
    Public Post As PostComApp
    Public Res As PostComProject
End Module
  • **[INotifyPropertyChanged](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged?view=netframework-4.7.2)** – Ňɏssa Pøngjǣrdenlarp Jan 09 '19 at 23:48
  • In case you have static classes and you can't implement an Interface, see this similar method: [How can I make the value of a variable track the value of another](https://stackoverflow.com/q/52685245/7444103). Right, it's `C#`, I don't know if you *speak the language*, but the procedure is quite simple. – Jimi Jan 09 '19 at 23:51
  • Just do it the same way as always: change your public field to private, add a public property and then raise an event in the setter of that property. The property is a member of the module so the event should be a member of the module too. You should be making sure that the value has actually changed before raising the event. – jmcilhinney Jan 10 '19 at 00:14
  • 1
    *"I tried with below method which made for an integer type parameter but i didnt succeded for my case"*. What did you actually try and what actually happened? That's not a question we should EVER have to ask because it should be part of your question as a matter of course. – jmcilhinney Jan 10 '19 at 00:16

0 Answers0