473,217 Members | 1,954 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,217 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 3135
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?...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.