473,386 Members | 1,819 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,386 software developers and data experts.

TimeSpan.Parse resulting in 00:00:00, why?

Hi,
I'm using the timespan's Parse method to build my timespan from a
string. here's the line I use :

m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))

the value I get from the RegKey is 00:00:30, so it should give a timespan of
30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00.
Am I doing something wrong?

thanks
Jul 21 '05 #1
9 3144
ThunderMusic,
| m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))

TimeSpan.Parse is a shared method that returns a new TimeSpan value.

TimeSpan itself is immutable (doesn't change).

Try something like:

m_Delay = TimeSpan.Parse(RegKey.GetValue("Delay", "01:00:00"))

Hope this helps
Jay

"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:OY*************@TK2MSFTNGP15.phx.gbl...
| Hi,
| I'm using the timespan's Parse method to build my timespan from a
| string. here's the line I use :
|
| m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))
|
| the value I get from the RegKey is 00:00:30, so it should give a timespan
of
| 30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00.
| Am I doing something wrong?
|
| thanks
|
|
Jul 21 '05 #2
I found it too. I had not seen the method was shared (static), so I juste
had to do the following :

m_Delay = TimeSpan.Parse(RegKey.GetValue("Delay", "01:00:00"))

Now it works fine.
"ThunderMusic" <NO*******@sympatico.caSPAMATALL> a écrit dans le message de
news:OY*************@TK2MSFTNGP15.phx.gbl...
Hi,
I'm using the timespan's Parse method to build my timespan from a
string. here's the line I use :

m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))

the value I get from the RegKey is 00:00:30, so it should give a timespan of 30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00.
Am I doing something wrong?

thanks

Jul 21 '05 #3
oh, I didn't see your answer before posting mine... thanks a lot for
answering.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> a écrit dans le
message de news:eG*************@TK2MSFTNGP12.phx.gbl...
ThunderMusic,
| m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))

TimeSpan.Parse is a shared method that returns a new TimeSpan value.

TimeSpan itself is immutable (doesn't change).

Try something like:

m_Delay = TimeSpan.Parse(RegKey.GetValue("Delay", "01:00:00"))

Hope this helps
Jay

"ThunderMusic" <NO*******@sympatico.caSPAMATALL> wrote in message
news:OY*************@TK2MSFTNGP15.phx.gbl...
| Hi,
| I'm using the timespan's Parse method to build my timespan from a
| string. here's the line I use :
|
| m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))
|
| the value I get from the RegKey is 00:00:30, so it should give a timespan of
| 30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00. | Am I doing something wrong?
|
| thanks
|
|

Jul 21 '05 #4
Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> wrote:
| m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))

TimeSpan.Parse is a shared method that returns a new TimeSpan value.

TimeSpan itself is immutable (doesn't change).

Try something like:

m_Delay = TimeSpan.Parse(RegKey.GetValue("Delay", "01:00:00"))


Just one example of why static (shared) methods shouldn't be callable
as if they were instance methods...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5
Jon,
| Just one example of why static (shared) methods shouldn't be callable
| as if they were instance methods...
I couldn't agree more. Fortunately VB.NET 2005 warns you when you attempt to
call a shared (static) method as an instance method.

Jay

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
| Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> wrote:
| > | m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00"))
| >
| > TimeSpan.Parse is a shared method that returns a new TimeSpan value.
| >
| > TimeSpan itself is immutable (doesn't change).
| >
| > Try something like:
| >
| > m_Delay = TimeSpan.Parse(RegKey.GetValue("Delay", "01:00:00"))
|
| Just one example of why static (shared) methods shouldn't be callable
| as if they were instance methods...
|
| --
| Jon Skeet - <sk***@pobox.com>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
Jul 21 '05 #6
> I couldn't agree more. Fortunately VB.NET 2005 warns you when you attempt
to
call a shared (static) method as an instance method.

And that is in my opinion the right approach. (I don't like the word
shouldn't). Although I see not any reason why it shouldn't. (I can see a
reason however that is against my way of writing a program and that is when
in the static/shared procedure a static/value is set).

:-)

Cor
Jul 21 '05 #7
Cor Ligthert <no************@planet.nl> wrote:
I couldn't agree more. Fortunately VB.NET 2005 warns you when you attempt
to call a shared (static) method as an instance method.
And that is in my opinion the right approach. (I don't like the word
shouldn't). Although I see not any reason why it shouldn't. (I can see a
reason however that is against my way of writing a program and that is when
in the static/shared procedure a static/value is set).


The reason you shouldn't (and I'm not afraid to use that word) is that
it gives the wrong impression. It gives the impression that the method
you're calling is related to the instance you appear to be calling it
on, when that simply isn't the case.

For instance, if you create a new Thread and then appear to call Sleep
on it, it *looks* like you're somehow telling the other thread to
sleep, when in fact it's making the current thread sleep.

Things which harm readability in this way really shouldn't be used.
Personally I think it would be better as an error than as a warning,
but I can see why changing it to an error at this stage would be a real
problem.

Of course, it's worth always trying to write code which doesn't
generate warnings anyway, and if you do that it doesn't really matter
whether it's a warning or an error...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #8
Jon,
| Things which harm readability in this way really shouldn't be used.
| Personally I think it would be better as an error than as a warning,
| but I can see why changing it to an error at this stage would be a real
| problem.
I just double checked. It defaults to a warning for new projects; using the
project properties you can change it to either: None, Warning, or Error.

FWIW: There are a handful of other compile messages, such as "unused local
variable" or "recursive operator & property access", that you can set to
None, Warning, or Error which is rather nice.

Jay

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
| Cor Ligthert <no************@planet.nl> wrote:
| > > I couldn't agree more. Fortunately VB.NET 2005 warns you when you
attempt
| > > to call a shared (static) method as an instance method.
|
| > And that is in my opinion the right approach. (I don't like the word
| > shouldn't). Although I see not any reason why it shouldn't. (I can see a
| > reason however that is against my way of writing a program and that is
when
| > in the static/shared procedure a static/value is set).
|
| The reason you shouldn't (and I'm not afraid to use that word) is that
| it gives the wrong impression. It gives the impression that the method
| you're calling is related to the instance you appear to be calling it
| on, when that simply isn't the case.
|
| For instance, if you create a new Thread and then appear to call Sleep
| on it, it *looks* like you're somehow telling the other thread to
| sleep, when in fact it's making the current thread sleep.
|
| Things which harm readability in this way really shouldn't be used.
| Personally I think it would be better as an error than as a warning,
| but I can see why changing it to an error at this stage would be a real
| problem.
|
| Of course, it's worth always trying to write code which doesn't
| generate warnings anyway, and if you do that it doesn't really matter
| whether it's a warning or an error...
|
| --
| Jon Skeet - <sk***@pobox.com>
| http://www.pobox.com/~skeet
| If replying to the group, please do not mail me too
Jul 21 '05 #9
Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> wrote:
| Things which harm readability in this way really shouldn't be used.
| Personally I think it would be better as an error than as a warning,
| but I can see why changing it to an error at this stage would be a real
| problem.
I just double checked. It defaults to a warning for new projects; using the
project properties you can change it to either: None, Warning, or Error.
Excellent.
FWIW: There are a handful of other compile messages, such as "unused local
variable" or "recursive operator & property access", that you can set to
None, Warning, or Error which is rather nice.


Very nice. I'm doing Java development as well as C# at the moment,
which means I'm being spoiled by how nice the Eclipse compiler is. It
has all kinds of optional errors/warnings. I'm being spoiled by Eclipse
in all kinds of other ways, too, but that's a different story.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #10

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

Similar topics

2
by: Jeff Shantz | last post by:
Hello, I'm developing a large statistics application for a call center. It often needs to calculate time spanning over months. For example, an agent's total talk time within 30 days. Since an...
9
by: ThunderMusic | last post by:
Hi, I'm using the timespan's Parse method to build my timespan from a string. here's the line I use : m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00")) the value I get from the RegKey is...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
3
by: RicercatoreSbadato | last post by:
I'd like to print a TimeSpan variable in this way: 00:00:00 --hh:mm:ss (whitout the milliseconds) how can I do it?
29
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
3
by: Jeff Jarrell | last post by:
I am unable to add up two timespans as created by the System.Diagnostics.Stopwatch class. Each stopwatch should be about two seconds and is appears ok, but when I try and add them up it goes to...
5
by: prasanta.bhowmik | last post by:
Hello, I created a object of TimeSpan only with minute and expected the result in hours and minute, but its returning wrong result. My Code is : TimeSpan timeSpan = new TimeSpan(0,2400,0);...
4
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column...
5
by: | last post by:
Why is it that: DateTime start = DateTime.Parse("1:00 AM"); DateTime stop = DateTime.Parse("2:30 AM"); TimeSpan ts = stop - start; Response.Write(ts.Minutes.ToString()); Produces 30, not 90?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.