473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with Format Function

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.
Dec 3 '06 #1
8 5501
Thunder,

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

Cor

"Thunder" <jr***@patmedia.netschreef in bericht
news:uY**************@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.

Dec 3 '06 #2
"Thunder" <jr***@patmedia.netschrieb:
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/>

Dec 3 '06 #3
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]" <hi***************@gmx.atwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
"Thunder" <jr***@patmedia.netschrieb:
>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/>

Dec 4 '06 #4
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?.
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
"Thunder" <jr***@patmedia.netschrieb:
>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/>

Dec 4 '06 #5
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?

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>"Thunder" <jr***@patmedia.netschrieb:
>>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.
Dec 4 '06 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>"Thunder" <jr***@patmedia.netschrieb:
>>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
Dec 4 '06 #7
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.

"Andrew Morton" <ak*@in-press.co.uk.invalidwrote in message
news:uU**************@TK2MSFTNGP06.phx.gbl...
>"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
>>"Thunder" <jr***@patmedia.netschrieb:
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

Dec 4 '06 #8
Stephany Young wrote:
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

Dec 4 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Anthony | last post by:
I am trying to get a users DN by translating the LOGON_USER NT4 format variable. I am ONLY using windows authentication for security settings: This is a Windows 2000 IIS 5 Server. Here is the...
2
by: Brad Pepers | last post by:
For the life of me I can't see why this code won't compile even though its very simple. Any hints? I get errors in NumberValcon::format(int) when it tries to call format() but why doesn't it use...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
0
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
5
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
1
by: swathichavalla | last post by:
Problem description: Clients working with an apple computer with the safari browser are experiencing problems with brokerage orders. When the client wants to enter a stock order, the order entry...
11
by: jessy | last post by:
Hi, I have a problem with my DateTimePicker javascript code which i downloaded , the problem is when i pick the date and the date appears in my Text Field and i click Submit the date which i picked...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.