10 Replies - 11426 Views - Last Post: 21 February 2008 - 01:58 PM Rate Topic: -----

#1 mikjall77   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 18-April 07

Error on Form.ShowDialog()

Posted 20 February 2008 - 10:50 PM

After doing a login screen, the user is supposed to go to an information screen. Before I even start everything up, I get the following error, "Reference to a non-shared member requires an object reference". I've had new screens "pop" up before and never have had an error like this. Any help on how I can fix this whether it's with Visual Studio, the code, or the propertire would be greatly appreciated!!!

Thank you in advanced,
Mike

Is This A Good Question/Topic? 0
  • +

Replies To: Error on Form.ShowDialog()

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Error on Form.ShowDialog()

Posted 20 February 2008 - 10:53 PM

What is the name of the class (form) that you instantiated?

In the future include your code when asking for help.
Was This Post Helpful? 0
  • +
  • -

#3 mikjall77   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 18-April 07

Re: Error on Form.ShowDialog()

Posted 20 February 2008 - 11:03 PM

View Postjayman9, on 20 Feb, 2008 - 10:53 PM, said:

What is the name of the class (form) that you instantiated?

In the future include your code when asking for help.

the name of my form is frmInformation and the code is:
frmInformation.ShowDialog()

Was This Post Helpful? 0
  • +
  • -

#4 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 12:26 AM

You cannot call a form directly by name, you must first instantiate an instance of it.

Dim myForm As New frmInformation

myForm.ShowDialog()

Was This Post Helpful? 0
  • +
  • -

#5 mikjall77   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 47
  • Joined: 18-April 07

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 01:46 AM

jayman,

Thank you for your help. I thought it was something like that, but for some reason, what I was originally putting in, VB didn't like it. I finally got it working though.

Thanks again for your help.
Was This Post Helpful? 0
  • +
  • -

#6 RodgerB   User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 03:04 AM

View Postjayman9, on 21 Feb, 2008 - 06:26 PM, said:

You cannot call a form directly by name, you must first instantiate an instance of it.


I disagree with this statement. This may be the case in C#, but not in VB.NET.

To prove my case, do the following to invoke a form without instantiating it yourself (step-by-step is how I roll, I know you don't need all the details but for the purpose of others learning too):

1) Create a new solution, name it InvokeForm, or something similar.
2) Rename the name of the form from Form1 to frmMain (for the purpose of readability).
3) Add a new form to the project. Name it frmOtherForm.
4) In frmMain, in the Form Load event add the following subroutine:

frmOtherForm.Show()



5) Build and Debug.

Putting my credibility on the line here, this is untested from my end, but I am very sure this works (on my Linux machine atm :D ). However as you know doing it from C# does require you instantiate the form.
Was This Post Helpful? 0
  • +
  • -

#7 Nayana   User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 32
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 03:58 AM

Oh right, I had no idea.

I've never touched VB.net, so I just assumed that they had to be instantiated myself.

I am now one piece of knowledge less ignorant.

This post has been edited by Nayana: 21 February 2008 - 03:59 AM

Was This Post Helpful? 0
  • +
  • -

#8 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 11:55 AM

View PostRodgerB, on 21 Feb, 2008 - 02:04 AM, said:

I disagree with this statement. This may be the case in C#, but not in VB.NET.

My answer is 100% correct, however perhaps I should elaborate a little more. You apparently did not read the error message that mikjall77 is receiving.

While it is true, RodgerB, that you can call a shared member directly by name, you cannot call a non-shared member directly.

Reference to a non-shared member requires an object reference error message

If you do not understand that concept of Shared in VB, then you can read all about it here.

The method that you are implementing is a shared member, so you are correct, as far as that goes.

I hope that this clarifies my answer.
Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 12:05 PM

This is definitely weird, in VB.Net Ive never had to instantiate a form to open it before. In fact here at work Im currently in a VB.Net application and we use FormName.ShowDialog() continually without creating a new instance of FormName. I know in C# I have to, but have never had to in VB.Net :blink:
Was This Post Helpful? 0
  • +
  • -

#10 RodgerB   User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 01:57 PM

I suppose the only logical cause is that mikjall77 changed the Modifiers property of the form. I too have never needed to instantiate a form in VB.NET.
Was This Post Helpful? 0
  • +
  • -

#11 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Error on Form.ShowDialog()

Posted 21 February 2008 - 01:58 PM

View PostPsychoCoder, on 21 Feb, 2008 - 11:05 AM, said:

This is definitely weird, in VB.Net Ive never had to instantiate a form to open it before. In fact here at work Im currently in a VB.Net application and we use FormName.ShowDialog() continually without creating a new instance of FormName. I know in C# I have to, but have never had to in VB.Net :blink:

I agree with you 100%, Richard. And personally I have never encountered the problem myself. This is only the second time that I have seen someone else have this specific problem in my experience as a coder. And the answer I provided as it relates to that specific error message is the only correct solution that I have ever found.

I wish that I could explain why/how it happens, but I cannot as I don't really understand it myself. I can only point you to the links I provided in my previous response.

I have never been able to duplicate the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1