Error: 'show' is not a member of 'MessageBox'

Solitaire

Well-known member
Joined
Jun 28, 2004
Messages
465
Location
New York
Programming Experience
10+
I teach VB in college, using the Express edition. I was doing an exercise with my class today using the MessageBox.Show() method in a Windows Forms application. But when I tried entering it in the edit window, it gave me the following error message:

'show' is not a member of 'MessageBox'


and it did not show up in the Intellisense box. Most of my students' computers did work with that method, but one or two of them didn't. Meanwhile, I had to revert to the MsgBox() function to get through the exercise.

Ironically, when running a prepared demo program that includes the MessageBox.Show() method on the school computer, it runs without a problem.

I remember having the same issue at school a year ago (I think we were using VB 2008 at the time). The issue was resolved but I don't remember what the solution was.

My home computer doesn't have that problem. However, I just copied the program from my school disk to my home computer. When I attemped to change the MsgBox() line to MessageBox.Show(), I got the same error message as I did in school:

'show' is not a member of 'MessageBox'

But when I copy and paste the code into a new application, it works correctly with MessageBox.Show().

How do I go about fixing this? The problem seems to be in the project I brought over from school. Does anyone have the solution? I will be back in my classroom on Wednesday and hopefully will be able to resolve the problem by then.
 
Hi Solitaire,

Try to add Imports System.Windows.Forms in your code window. Maybe the namespace of that Class is not initialize thats why.

Please see code below for your reference.

VB.NET:
Imports System
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms


...


' Display a message box with a help button. 
' The Help button opens the Mspaint.chm Help file.
Dim r1 As DialogResult = MessageBox.Show("Message with Help file.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, _
                                   "mspaint.chm")
 
My guess is that you have a name clash. Have you named your project "MessageBox" by any chance? If so then, when you type 'MessageBox' into the code window, the compiler interprets it as the root namespace of your project rather than the MessageBox class. In that case you need to either:

1. Change the root namespace of your project to something else. The root namespace is the same as the project name initially but you can change it to anything you like. I suggest that all root namespaces be at least two parts, e.g. CompanyName.ApplicationName. The company name might be your school name or each students own name. That way, they will never clash with anything.

2. The name that gets hidden can be qualified, i.e. use Windows.Forms.MessageBox to refer to the WinForms MessageBox class.
 
Thank you, jm. That is exactly right. I had named my project "MessageBox" and it conflicted with the method name.

Now I remembered that was the same problem and solution I had last semester. I checked my journal notes from last semester and saw that you had correctly identified the problem and offered the solution back then. So I now have to thank you twice. I revised my lecture notes so that problem will not come up again in the future.
 
When I saw this thread, I thought it was your old thread that had been bumped up, Solitaire, as I remembered it from last time. I didnt have the heart to tell you to search your old posts :D

Oh, and jmc always speaks wise words - in his last post on the original thread, he said

If you hang around forums like this one long enough then you're bound to see everything at least once

Let's just hope it never changes to

If you hang around forums like this one long enough then you're bound to post everything at least twice

:cool:
 
Inertia, thank you for your observation and insight. I guess I'm getting old and my memory is failing. I actually didn't remember having posted the problem here last semester. I thought it had been solved by one of the school administrators.
 
Back
Top