I created a new Class Library, and want to use the MessageBox.Show function within a procedure in the class. Maybe this can't be done? I tried adding "Imports System.Windows.Forms" to the top of the class module, but it won't allow me to use that, either. Here's a simplified version of my code in the Class Library:

Public Sub Msg(strMessage as string, strTitle as string)
Messagebox.Show(strMessage, strTitle)
end sub

If you're wondering why I'm doing this, it's because as often as I use the MessageBox function, I want something simpler and easier to type. I want to use Msg() in any of the applications I write.

Thanks ahead of time,
Sheryl

I'm replying to my own post so I can put my code in properly. Sorry, I'm a newbie. Would sure appreciate some responses to my problem. Thanks!

Public Sub Msg(strMessage as string, strTitle as string)
     Messagebox.Show(strMessage, strTitle)
end sub

If your class is part of a windows GUI application you won't even need to import that namespace and your code works.

So I assume you're creating a standalone dll. First you have to add reference to System.Windows.Forms.dll. From "Project"-menu select "Add Reference". From ".NET"-tab locate System.Windows.Forms, select it and press "Ok"-button. Now import namespace Imports System.Windows.Forms and your code works as you want.

It works! Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.