471,357 Members | 1,175 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 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 2939
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jeff Shantz | last post: by
9 posts views Thread by ThunderMusic | last post: by
3 posts views Thread by RicercatoreSbadato | last post: by
29 posts views Thread by gs | last post: by
3 posts views Thread by Jeff Jarrell | last post: by
5 posts views Thread by prasanta.bhowmik | last post: by
5 posts views Thread by | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.