Home All Groups Group Topic Archive Search About

Problem with Format Function

Author
3 Dec 2006 5:14 PM
Thunder
Hi All,
I'm using VB.Net 2005.  I have for years used Format to format strings and
dates, etc...
Now when I try to use Format I get the following error?

"'Format' is a type and can not be used as an expression"

Can anyone help?

Thanks,
John.

Author
3 Dec 2006 5:41 PM
Cor Ligthert [MVP]
Thunder,

Probably as you show the code that you are using.
This kind of questions are popular.

Cor

Show quoteHide quote
"Thunder" <jr***@patmedia.net> schreef in bericht
news:uYKXy5vFHHA.4712@TK2MSFTNGP04.phx.gbl...
> Hi All,
> I'm using VB.Net 2005.  I have for years used Format to format strings and
> dates, etc...
> Now when I try to use Format I get the following error?
>
> "'Format' is a type and can not be used as an expression"
>
> Can anyone help?
>
> Thanks,
> John.
>
Author
3 Dec 2006 10:36 PM
Herfried K. Wagner [MVP]
"Thunder" <jr***@patmedia.net> schrieb:
> I'm using VB.Net 2005.  I have for years used Format to format strings and
> dates, etc...
> Now when I try to use Format I get the following error?
>
> "'Format' is a type and can not be used as an expression"


Unfortunately 'Format' cannot be used to format strings any more.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
4 Dec 2006 1:51 AM
Thunder
Ok,
then what is to replace it?

I used to be able to write
dim STR as String = Format(Now(), "MM/dd/yyyy")

What would I write now?

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uAQ1GuyFHHA.1248@TK2MSFTNGP02.phx.gbl...
> "Thunder" <jr***@patmedia.net> schrieb:
>> I'm using VB.Net 2005.  I have for years used Format to format strings
>> and dates, etc...
>> Now when I try to use Format I get the following error?
>>
>> "'Format' is a type and can not be used as an expression"
>
>
> Unfortunately 'Format' cannot be used to format strings any more.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
4 Dec 2006 3:02 AM
ShaneO
Thunder wrote:
Show quoteHide quote
> Ok,
> then what is to replace it?
>
> I used to be able to write
> dim STR as String = Format(Now(), "MM/dd/yyyy")
>
> What would I write now?
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:uAQ1GuyFHHA.1248@TK2MSFTNGP02.phx.gbl...
>> "Thunder" <jr***@patmedia.net> schrieb:
>>> I'm using VB.Net 2005.  I have for years used Format to format strings
>>> and dates, etc...
>>> Now when I try to use Format I get the following error?
>>>
>>> "'Format' is a type and can not be used as an expression"
>>
>> Unfortunately 'Format' cannot be used to format strings any more.
>>
>> --
>> M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
>

I don't know why you feel you can't use Format (or why you're being told
you can't) but the following works perfectly for me! -

Dim sString As String = Format(Now, "MM/dd/yyyy")
Debug.Print(sString)

Maybe post the code you're having problems with so we can see where you
might be going wrong.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Author
4 Dec 2006 11:01 AM
Andrew Morton
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:uAQ1GuyFHHA.1248@TK2MSFTNGP02.phx.gbl...
>> "Thunder" <jr***@patmedia.net> schrieb:
>>> I'm using VB.Net 2005.  I have for years used Format to format
>>> strings and dates, etc...
>>> Now when I try to use Format I get the following error?
>>>
>>> "'Format' is a type and can not be used as an expression"
>>
>>
>> Unfortunately 'Format' cannot be used to format strings any more.

Thunder wrote:
> Ok,
> then what is to replace it?
>
> I used to be able to write
> dim STR as String = Format(Now(), "MM/dd/yyyy")
>
> What would I write now?

[Please put your reply *after* the text you're quoting.]

DateTime.Today.ToString("yyyy-MM-dd")

Or it may be that you don't have "Imports System.String" to tell it which
bit of namespace to look in for the Format method.

Always put "Option Strict On" at the top so it knows to tell you when it's
unsure of something.

Andrew
Author
4 Dec 2006 11:19 AM
Thunder
Thanks,
That is what I was looking for.
The DateTime.Parse(<datevalue>).Tostring("MM/dd/yyyy")
returns the correct value.

I have used format I think since version 4 of VB, I just recently switched
from VS.NET 2003 to 2005 and ran into this situation.  So if someone is able
to get Format working in VS.NET 2005, I don't know what my problem is?

Thanks all for you help.

Show quoteHide quote
"Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message
news:uUPbqO5FHHA.1188@TK2MSFTNGP06.phx.gbl...
>> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
>> news:uAQ1GuyFHHA.1248@TK2MSFTNGP02.phx.gbl...
>>> "Thunder" <jr***@patmedia.net> schrieb:
>>>> I'm using VB.Net 2005.  I have for years used Format to format
>>>> strings and dates, etc...
>>>> Now when I try to use Format I get the following error?
>>>>
>>>> "'Format' is a type and can not be used as an expression"
>>>
>>>
>>> Unfortunately 'Format' cannot be used to format strings any more.
>
> Thunder wrote:
>> Ok,
>> then what is to replace it?
>>
>> I used to be able to write
>> dim STR as String = Format(Now(), "MM/dd/yyyy")
>>
>> What would I write now?
>
> [Please put your reply *after* the text you're quoting.]
>
> DateTime.Today.ToString("yyyy-MM-dd")
>
> Or it may be that you don't have "Imports System.String" to tell it which
> bit of namespace to look in for the Format method.
>
> Always put "Option Strict On" at the top so it knows to tell you when it's
> unsure of something.
>
> Andrew
>
Author
4 Dec 2006 2:54 AM
Stephany Young
Hmmm........

VS2005 - VB.NET

Add button to form

Add handler for Click event of button

Add the following to the event handler:

  Dim STR As String = Format(Now(), "MM/dd/yyyy")
  Console.Writeline(STR)

Press F5

Click the button and magically 12/04/2006 appears in the output window.

How can that happen if 'Format' cannot be used to format strings any more?.


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uAQ1GuyFHHA.1248@TK2MSFTNGP02.phx.gbl...
> "Thunder" <jr***@patmedia.net> schrieb:
>> I'm using VB.Net 2005.  I have for years used Format to format strings
>> and dates, etc...
>> Now when I try to use Format I get the following error?
>>
>> "'Format' is a type and can not be used as an expression"
>
>
> Unfortunately 'Format' cannot be used to format strings any more.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
4 Dec 2006 5:13 PM
Chris Dunaway
Stephany Young wrote:
Show quoteHide quote
> Hmmm........
>
> VS2005 - VB.NET
>
> Add button to form
>
> Add handler for Click event of button
>
> Add the following to the event handler:
>
>   Dim STR As String = Format(Now(), "MM/dd/yyyy")
>   Console.Writeline(STR)
>
> Press F5
>
> Click the button and magically 12/04/2006 appears in the output window.
>
> How can that happen if 'Format' cannot be used to format strings any more?.
>

In addition, you can use String.Format for complex formatting:

Dim str As String = String.Format("The current date is {0:MM/dd/yyyy}",
DateTime.Now)
Console.WriteLine(str)

Chris