locked
MessageBox.Show is not declared (not found in library?)

    Question

  • 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 a message similar to the one above, 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, 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, so I don't know exactly how to approach the problem.  Does anyone have the solution for me?  I will be back in my classroom on Wednesday and try to work it out then.

    Thank you.
     


    Solitaire
    Tuesday, March 01, 2011 12:43 AM

Answers

  • Problem solved. 

    I had named my project "MessageBox" and it conflicted with the method name.  When I typed "MessageBox" into the code window, the compiler interpreted it as the root namespace of my project rather than the MessageBox class.   Using a different project name, or changing the root namespace solved the problem.

    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 someone had correctly identified the problem and offered the solution back then.  I revised my lecture notes so that problem will not come up again in the future.


    Solitaire
    • Marked as answer by Solitaire Tuesday, March 01, 2011 5:56 PM
    Tuesday, March 01, 2011 5:56 PM

All replies

  • Sorry, the title of this thread is not exactly correct.  I didn't remember exactly what the error message was.

    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'

    However, 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.

    Here is the code (I was teaching the class how to use dialog boxes with the Select Case block:

    	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    		Dim color, fruit As String
    		color = InputBox("Did you buy a red, yellow, or blue fruit?")
    		color = color.ToLower()
    		Select Case color
    			Case "red"
    				fruit = "apple"
    			Case "yellow"
    				fruit = "banana"
    			Case "blue"
    				fruit = "plum"
    			Case Else
    				fruit = ""
    		End Select
    		MessageBox.Show("You bought a " & color & " " & fruit)
    	End Sub
    

    Solitaire
    Tuesday, March 01, 2011 2:22 AM
  • Problem solved. 

    I had named my project "MessageBox" and it conflicted with the method name.  When I typed "MessageBox" into the code window, the compiler interpreted it as the root namespace of my project rather than the MessageBox class.   Using a different project name, or changing the root namespace solved the problem.

    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 someone had correctly identified the problem and offered the solution back then.  I revised my lecture notes so that problem will not come up again in the future.


    Solitaire
    • Marked as answer by Solitaire Tuesday, March 01, 2011 5:56 PM
    Tuesday, March 01, 2011 5:56 PM