Search code examples
vb.netvisual-studiovisual-studio-2017

How to implement a custom DLL I made with Public Subs


I am working on making my own game, and I want to implement a custom DLL that I have made. It uses custom Public Sub arguments, and it seems that I can't implement it properly. The code for the DLL goes like this:

Public Class EventChanger
    Public Sub StopEvent()
        'code here to stop event
    End Sub
    Public Sub StartEvent()
        'code here to start event
    End Sub
End Class

I compiled it, and added the reference to it, and added the code to it.

Imports EventChanger

And when I make the code it looks like this:

Imports EventChanger
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        EventChanger.EventChanger.StopEvent()
        'other code
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'other code unrelated to event
    End Sub
End Class

I get a error like this, so then I tried this:

Imports EventChanger

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        EventChanger.StopEvent()
        'other code
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        'other code unrelated to event
    End Sub
End Class

But I still get an error. Could someone help me? Thanks!


Solution

  • Changing the code to

    Public Class EventChanger
        Public Shared Sub StopEvent()
            'code here to stop event
        End Sub
        Public Shared Sub StartEvent()
            'code here to start event
        End Sub
    End Class
    

    Worked. Now I can do the following code:

    Imports EventChanger
    

    And when I make the code it looks like this:

    Imports EventChanger
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            EventChanger.EventChanger.StopEvent()
            'other code
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            'other code unrelated to event
        End Sub
    End Class
    

    This works for me.