Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 86,253 VB.NET Programmers. There are 2,134 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a VB.NET Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Error Using TimeSpan.Parse( string )

 
Reply to this topicStart new topic

Error Using TimeSpan.Parse( string )

rfinks
post 23 Sep, 2007 - 07:16 AM
Post #1


New D.I.C Head

*
Joined: 22 Sep, 2007
Posts: 2



I am attempting to convert a string which is in a format of "dd:hh:mm:ss" to a TimeSpan. I received the following error message:

System.FormatException was unhandled by user code
Message="Input string was not in a correct format."
Source="mscorlib"
StackTrace:
at System.TimeSpan.StringParser.Parse(String s)
at System.TimeSpan.Parse(String s)
at Time.ToTimeSpan() in C:\Inetpub\wwwroot\MediaCenter\App_Code\Time.vb:line 101
at MusicTrack.MusicTrackMaint.SetTrackData() in C:\Inetpub\wwwroot\MediaCenter\MusicTrackMaint.ascx.vb:line 146
at MusicTrack.MusicTrackMaint.btnOK_OnClick(Object s, EventArgs e) in C:\Inetpub\wwwroot\MediaCenter\MusicTrackMaint.ascx.vb:line 98
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Following is my code which is copied from .NET Framework Class Library:
CODE

   Public Function ToTimeSpan() As TimeSpan
        Dim timeSpanToString As String = "0:" & Hour & ":" & Minute & ":" & Second
        Dim timeSpanToTS As TimeSpan = TimeSpan.Parse( timeSpanToString )
        Return timeSpanToTS
   End Function


The error was on the 2nd Dim statement
Hour = 0
Minute = 15
Second = 36

When I hover over timeSpanToString it shows content of "0:0:15:36"

Thanks
Roger
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


PsychoCoder
post 23 Sep, 2007 - 08:01 AM
Post #2


ToCode || !ToCode

Group Icon
Joined: 26 Jul, 2007
Posts: 5,857

I will look into your problem shortly, but right now I am moving this to the VB.Net Forum, as thats where it belongs smile.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

orcasquall
post 23 Sep, 2007 - 08:47 AM
Post #3


D.I.C Head

Group Icon
Joined: 14 Sep, 2007
Posts: 139

Try this
CODE

Dim timeSpanToString As String = "0." & Hour & ":" & Minute & ":" & Second

The days part should be followed by a period "." instead of the semicolon ":".

Refer to the MSDN documentation for TimeSpan.Parse() for more information:
.NET Framework 1.1 and .NET Framework 3.0
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

WALDO
post 6 May, 2008 - 08:51 AM
Post #4


New D.I.C Head

*
Joined: 6 May, 2008
Posts: 1

CODE

Dim timeSpanToString As String = "0[b][color=#FF0000].[/color][/b]" & Hour & ":" & Minute & ":" & Second
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 09:20AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month