TimeSpan + Date.Add() Issue

  • Thread starter Thread starter Miro
  • Start date Start date
M

Miro

Using VB.net vs2008
Looking at the two lines below, why does the first line not work, and the
other does.

No compile error, the debug "diffDate" has a value. Lets say (10
seconds)...
but the .add does not seem to add the timespan into the countdatetimeto

..Add( Paramter is a requried timespan value )

Dim diffDate As TimeSpan = PausedEndDateTime -
PausedStartDateTime
Dim origdatetimeto = CountDateTimeTo 'For debugging
purposes quicktest
'CountDateTimeTo.Add(diffDate) ***** this does not work
CountDateTimeTo = CountDateTimeTo + diffDate ***** this
does


Thanks,

Miro
 
Miro said:
Using VB.net vs2008
Looking at the two lines below, why does the first line not work, and
the other does.

No compile error, the debug "diffDate" has a value. Lets say (10
seconds)...
but the .add does not seem to add the timespan into the
countdatetimeto

.Add( Paramter is a requried timespan value )

Dim diffDate As TimeSpan = PausedEndDateTime -
PausedStartDateTime
Dim origdatetimeto = CountDateTimeTo 'For debugging
purposes quicktest
'CountDateTimeTo.Add(diffDate) ***** this does not
work

Add is a function. It returns the new value.


Armin
 
Miro,

It is hard to say as long as we don't know what type CountDateTimeTo is.

Although it seems to be a kind of value type and those don't have basicy an
..Add member.

Cor
 
I basically created a form with a button on it.

On form load i set DateTimeFrom = Now()

and on the button click i set DateTimeTo = Now()
and executed the code below.

So they were both valid dates and debugging showed them as dates.

Stepping through each line one by one, the one line did no changes on
variables ( with watch ), and the other did.

Miro
 
Crap...

I can't beleive I didn't catch that.

Sorry for the post - and thanks for the answer.

Miro
 
Check out Armin's Post,

I have a logical bug/error in there.
..Add returns a value, it doesnt assign it within.

The variable was declared as date.

I made a dumb error where I didnt realize it was not assigning a value right
away.

Miro
 
Back
Top