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