Results 1 to 10 of 10

Thread: VB.NET: MsgBox vs Messagebox.Show...

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2002
    Posts
    88

    VB.NET: MsgBox vs Messagebox.Show...

    VB.NET: MsgBox vs Messagebox.Show...
    This is a VERY small issue, but it's confusing me. I doubt anyone, including myself, will be losing sleep (possibly gaining some).

    I'm reading a VERY BASIC VB.NET book (it's turning out to not be so basic - a new comer would have given up by now), and the author uses the MsgBox function to display simple messages in very simple VB.NET programs.

    The strange thing is that the useability of 'MsgBox' in my VB.NET seems to be inconsistent: in one project, VB recognized the 'MsgBox' function, put up the intellisense formation of the function, and all was well ('MsgBox' was within a click event).

    Next, when I started a new project and put 'MsgBox' within the 'form_load' event, the text was underlined as if it wasn't validated or recognized, and when I ran the program anyway I received the build error: "'MsgBox' is a namespace, and so it is not a valid expression."

    So, am I doing something wrong or is the author of this book forgetting some detail? I can switch between my 2 projects and add in MsgBoxes to the 1st one, but the 2nd one never accepts them. Both programs like the more VB.Nettish 'Messagebox.show' control. Why didn't the author use this one?

    I'm confused, but, again, this is not a big issue.

    Thanks,

    Ed

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    MsgBox is there for backward compatibilty. Its located in the Microsoft.VisualBasic namespace. It is recommended that you use MessageBox.Show.
    Dont gain the world and lose your soul

  3. #3
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    MessageBox.show is actually a windows form class. but since VB has a built in msgbox function you dont really need to use the Messagebox.show stuff. But they are pretty much identicle.

  4. #4
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by DevGrp
    MsgBox is there for backward compatibilty. Its located in the Microsoft.VisualBasic namespace. It is recommended that you use MessageBox.Show.
    true, but why is he getting that funky intermittent behavior? msgbox should still work even though it isnt recommended.

    Kinda strange that a book would be teaching its use without explaining the backward compatability and Microsoft.Visual namespace.

    Trash that book and get hold of a copy of Kark Moore's "visual basic .net: the tutorials"

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    true, but why is he getting that funky intermittent behavior? msgbox should still work even though it isnt recommended.
    The reason for that is because he needs to import the Microsoft.VisualBasic namespace.

    Put this statement
    VB Code:
    1. imports Microsoft.VisualBasic
    at the beggining of the file you want to use the MsgBox function in.
    Dont gain the world and lose your soul

  6. #6
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    when ever i make a new project or module in VB.net i never have to do anything to get msgbox to work, it just does.

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    MessageBox.show is actually a windows form class. but since VB has a built in msgbox function you dont really need to use the Messagebox.show stuff. But they are pretty much identicle.
    Well, actually he needs to use MessageBox.Show. If he writes a control in VB.NET and uses the MsgBox function, that would be bad if that control was used in C# or any other language that targets the .NET Framework. MS recommends that you avoid the Microsoft.VisualBasic namespace. Its only there for backwards compatibility with previous versions of VB and for the upgrade wizard.
    Dont gain the world and lose your soul

  8. #8
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Cecilton, MD USA
    Posts
    278
    thats true but it sounds as if he is a beginner and most likely wont be using controls made in vb .net in c# any time soon. most books now tell you to use msgbox

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Well those books needs to be tossed out the window.
    Dont gain the world and lose your soul

  10. #10
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by DevGrp
    Well those books needs to be tossed out the window.
    Microsoft agrees with you anyway . See the note about 2/3 the way down on the following page:

    http://msdn.microsoft.com/library/de...ssageBoxes.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width