|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with Format FunctionHi 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. 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. > "Thunder" <jr***@patmedia.net> schrieb: Unfortunately 'Format' cannot be used to format strings any more.> 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" -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> 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/> Thunder wrote:
Show quoteHide quote > Ok, I don't know why you feel you can't use Format (or why you're being told > 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/> > > 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. > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message Thunder wrote:> 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. > Ok, [Please put your reply *after* the text you're quoting.]> 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? 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 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 > 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/> Stephany Young wrote:
Show quoteHide quote > Hmmm........ In addition, you can use String.Format for complex formatting:> > 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?. > Dim str As String = String.Format("The current date is {0:MM/dd/yyyy}", DateTime.Now) Console.WriteLine(str) Chris
Question
About deleting file on Vista 64bit how to delete a ComboBox item Database Connection Designer Variables Newbie: error trying to save directory path to database Key Validation Need some Simple Help knowing when a form is accepted??????????? Get property at runtime Fax numbers Re: Upgrading Access 97 application to dotNet |
|||||||||||||||||||||||