Format enum type problem in Module

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

Hello,

The following code works in a Form class module but not a
standard module:
Dim d1 As DateTime
Format(d1, "MMMM")

In a standard module I get a squigly line saying that an
argument has not been specified for parameter format...
So I tried this:

Format(GetType(DateTime), d1, "MMMM")

but now I get the error message that the type provided
must be an enum. Any suggestions appreciated how I could
resolve this. What do I have to enumerate?

Thanks,
Ron
 
Ron said:
The following code works in a Form class module but not a
standard module:
Dim d1 As DateTime
Format(d1, "MMMM")

In a standard module I get a squigly line saying that an
argument has not been specified for parameter format...
So I tried this:

Format(GetType(DateTime), d1, "MMMM")

but now I get the error message that the type provided
must be an enum. Any suggestions appreciated how I could
resolve this. What do I have to enumerate?

What imports do you have in your form and in your module?
 
I have

Imports System.Data.OleDb
Imports System.IO

in the Form

and in the Standard Module I have

Imports System
Imports System.Data.OleDb

I added Imports System.IO to the standard module, but that
did not help anything. Any ideas?

Thanks
 
I left out that I was also importing

Imports Domino

When I commented that out then the squigly line went away
from the Format function. So there appears to be some
conflict with the Lotus Notes Domino Object Library and
the Format function. Is there a workaround for this?
 
Ron,
The "easiest" workaround is to favor DateTime.ToString (& other overridden &
overloaded Object.ToString methods) over VB.Format.

Dim d1 As DateTime
Dim s As String = d1.ToString("MMMM")

The biggest advantage being is you can overload & override ToString in your
own classes, which the promotes consistency, if you cannot overload
VB.Format and still use an Format without qualification.

If you do need to use the VB runtime functions, you can use an Import Alias:

Import VB = Microsoft.VisualBasic

Dim d1 As DateTime
Dim s As String = VB.Format(d1, "MMMM")

Hope this helps
Jay
 
Thank you very much. This is great information. I have
so much to learn about .Net. Your method is way better
than using the Format function.

No squigly lines or anything now :).

Thanks,
Ron
 

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