none
message box in visual basic 2010 code not working

    Question

  • hi all,

    i have visual studio ultimate 2010 and i was using visual basic and when i tried the messagebox.show command it does not work , am i missing any libraries that need to be installed

    or did they change this command , if i am missing some libraries , is there a patch or something that needs to be setup. i would appreciate if someone helps me regarding this matter.

    Regards,

    Amr

     

     

    Sunday, May 01, 2011 10:26 PM

Answers

  • MessageBox and (its Show method) are still there. It is in the System.Windows.Forms namespace. Are you creating a Windows Forms application? If not (e.g. if it's a Console Application) you may not have a reference to the library.
    Sunday, May 01, 2011 10:40 PM
  • Am I missing something here?  Why go to all that effort when all you need to do is add a reference to System.Windows.Forms in your console app, then call MessageBox.Show as shown below:
     
    Module Module1
     
        Sub Main()
            System.Windows.Forms.MessageBox.Show("Hi!")
        End Sub
     
    End Module

     

    --
    Mike
    Monday, May 02, 2011 12:30 AM

All replies

  • MessageBox and (its Show method) are still there. It is in the System.Windows.Forms namespace. Are you creating a Windows Forms application? If not (e.g. if it's a Console Application) you may not have a reference to the library.
    Sunday, May 01, 2011 10:40 PM
  • On 5/1/2011 6:26 PM, Amroooooo wrote:
    > hi all,
    >
    > i have visual studio ultimate 2010 and i was using visual basic and when
    > i tried the messagebox.show command it does not work , am i missing any
    > libraries that need to be installed
    >
    > or did they change this command , if i am missing some libraries , is
    > there a patch or something that needs to be setup. i would appreciate if
    > someone helps me regarding this matter.
    >
     
    Of course, this only works with a Windows form application.
     
    Sunday, May 01, 2011 11:24 PM

  •  
    Of course, this only works with a Windows form application.
     

    Hi darnold924,

    Not forgetting this also works with a WPF application.    :-)

    >>

    Class Window1 
    
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    
        MessageBox.Show("Hi there!!")
    
      End Sub
    End Class
    

     

    2)a) A Class library application if you add a reference and Import System.Windows.Forms

    >>

    Imports System.Windows.Forms
    
    Public Class Class1
    
      Public Sub Test()
    
        MessageBox.Show("Hi there!!")
    
      End Sub
    
    End Class
    

     

    Then you can call the Public Sub Test from a Windows Form based application

    after adding a reference to the DLL you generate with the above code.

     

    Here the DLL project is called DLLTest1

    >>

     

    Imports DLLTest1
    
    Public Class Form1
    
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        Dim cl1 As New Class1
        cl1.Test()
    
      End Sub
    End Class
    

    or

    2)b) A CONSOLE APPLICATION after adding a reference to the DLL you have created as at the top of this Section 2) .>>

     

    Imports DLLTest1
    
    Module Module1
    
      Sub Main()
    
        Dim cl1 As New Class1
        cl1.Test()
    
      End Sub
    
    End Module
    

     

    2)c) You could of course also call the Sub called Test from a WPF application.  :-)



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7
    Monday, May 02, 2011 12:20 AM
  • Am I missing something here?  Why go to all that effort when all you need to do is add a reference to System.Windows.Forms in your console app, then call MessageBox.Show as shown below:
     
    Module Module1
     
        Sub Main()
            System.Windows.Forms.MessageBox.Show("Hi!")
        End Sub
     
    End Module

     

    --
    Mike
    Monday, May 02, 2011 12:30 AM
  • Hi Mike,

    No, you are not missing something, I'm just showing how you could do it via a DLL as well.    ;-)    :-D

    Thanks for your input to this thread too.    :-)



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7
    Monday, May 02, 2011 12:39 AM
  • What does "does not work" mean in your context?  Are you getting an error message?  Is it failing to compile?  Without this information, we can only guess.  Like the others alluded to, make sure you have referenced the System.Windows.Forms assembly and imported the namespace.  Then it should work.
    Monday, May 02, 2011 6:49 PM