TimeSpan + Date.Add() Issue

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
 
A

Armin Zingler

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
 
C

Cor Ligthert[MVP]

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
 
M

Miro

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
 
M

Miro

Crap...

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

Sorry for the post - and thanks for the answer.

Miro
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top