Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

In my startup form called formMain I create a new instance of FormEdit. When I close this form I want to call a function in formMain. When I try formMain.functionname () I'm getting the error: Reference to a non-shared member requires an object reference.....

 

Can somebody help me with this?

 

ThanX

 

Grtz Drizzt

  • *Experts*
Posted
You need to use your instance of the form, not the form class itself.
Dim f As New FormMain
f.Method() '<-- Valid

FormMain.Method() '<-- Invalid if the Method is not declared "Shared"

Posted
Thanx for your reply. But since formMain is the startup form, I guess an instance of FormMain is automatically created when the application starts.... I also tried to make the function shared. But then I have to replace all the Me. statements in my function for an expliciet instance name. Is there no other way?
Posted
So you're calling your main form from another form? You'll have to pass an instance of FormMain to FormEdit (using the constructor would be best).
Gamer extraordinaire. Programmer wannabe.
  • *Experts*
Posted

YOu would have to edit the constructor of your second form:

'a variable to store the instance
Dim mainform As FormMain
Public Sub New(ByVal form1 As FormMain) 'accept a form instance
MyBase.New()
InitializeComponents()
mainform = form1 'set the passed in instance to the local variable

Then in your second form you can use the mainform variable to access the instance that was passed in.

And to declare your second form you need to do this:

Dim editform As New FormEdit(Me)
'using Me becasuse Im assuming you call this from your FormMain

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...