0

Whenever I try to open a form inside a DLL library, it returns "Reference to an non-shared member requires an object reference", even if it is in the same Class. If I try to replace the name of the form with Me (When it is in the same class), I get ""Me" is only within an instance method". Here is the code :

Public Class Prompt
    Shared Function open_prompt()
        Prompt.Show()
    End Function
 End Class

Any help would be appreciated

Null_
  • 33
  • 1
  • 4
  • 1
    You need to create an instance of the Prompt class, then you can call Show on that instance's variable _Dim p = new Prompt() _ p.Show()_ – Steve Apr 27 '18 at 15:54
  • 1
    AFAIK default form instances work only in WinForms _**applications**_. Class libraries (DLLs) doesn't seem to have this feature so you should do as @Steve said and create an instance of the form first (Steve: you should write that as an answer by the way). – Visual Vincent Apr 27 '18 at 17:40
  • 2
    @VisualVincent has been told many times here. Best point to a more complete answer like this one https://stackoverflow.com/questions/24906660/when-are-default-form-instances-created or this one https://stackoverflow.com/questions/4698538/why-is-there-a-default-instance-of-every-form-in-vb-net-but-not-in-c – Steve Apr 27 '18 at 17:49
  • This is more of a matter of being in a static vs. instance context. Does the method need to be marked `Shared`? I'd remove that, then change `Prompt.Show()` to `Me.Show()`. Still, I guess you are calling this method like `Prompt.open_prompt()`, then why you can't just do `Prompt.Show()` (though it is ill-advised to use the default form instance... ) is beyond me. – djv Apr 27 '18 at 18:19
  • Steve´s answer worked perfectly (thanks). Just one more thing I would like to ask, please put it in answers. – Null_ May 05 '18 at 12:18

0 Answers0