"Imports Microsoft.VisualBasic" doesn't import

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I've built a control. At the top of my control, I have this:

Imports Microsoft.VisualBasic

Then, later, I call a function like this:

DateTime.Now.Year.ToString()

This works fine on my machine. My coworker takes the exact same file,
compiles it, and gets errors until he explicitly writes out the function as:
microsoft.VisualBasic.DateAndTime.Now.Year.ToString()

Why?

This has happened before and only seems to affact the microsoft.VisualBasic
namespace. On his computer, it just doesn't seem to import it.

-Darrel
 
microsoft.VisualBasic.DateAndTime.Now.Year.ToString()

Why?
DateTime is a System.ValueType
This has happened before and only seems to affact the microsoft.VisualBasic
namespace. On his computer, it just doesn't seem to import it.

He'd also have to use a M instead of a m for it to work. Are you
using this name space for anything in particular cause I don't think
you need it in most cases.

-Adam
 
The frameowk is probably getting confused because that function doesn't
require the VisualBasic library at all. You can say the exact same thing
with System.DateTime.Now.Year.ToString(). If the System and
Microsoft.VisualBasic namespaces are both imported, how does the
DateTime.Now.Year.ToString() code know which namespace you are referencing?
It doesn't, which is why it generates the error unless the VisualBasic
namespace is specified as then there isn't any confusion by the compiler.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top