Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with time

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
Who would have thought working with times would be so hard? This is what I've been having problem with for a few days and I'm absolutely dumbfounded!

The second msgbox shows the right time, almost. Since it's trimming down characters, if it's more than 10 seconds it cuts it off to just one digit.

So I tried to fix that problem with Format:ing the string but it literally prints out: #.### instead of the numbers. I think part of the problem is it's in DateTime format and it has 0:0:0 or such prepended to the time.

I am SO confused and not making any progress on this timer.


Code:
    Dim _startTime As DateTime
    Dim _stopTime As DateTime

.
.
.
            _stopTime = Now ' intiate the endtime NOW
            Dim _totalSeconds As String
            _totalSeconds = _stopTime.Subtract(_startTime).ToString
            MsgBox((Format(_totalSeconds, "#.###")))
            _totalSeconds = _totalSeconds.ToString().Remove(0, 7)
            '_totalSeconds = _totalSeconds.ToString().Remove(2, 3)
            MsgBox("Reaction time = " + _totalSeconds + " sec")
 
try the timespan thingie

something like this

Code:
Dim _totalseconds As Long = DateDiff(DateInterval.Second, OldTime, NewTime)

and that you can format the way you did

Code:
MsgBox((Format(_totalSeconds, "#.###")))


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Hi.

That doesn't do it either. That is only as accurate as per one whole second. At this rate I almost think it'd be better to forget about VB.net entirely. There are many "issues" with it and it seems C/++ would be a better use of time.
 
It looks like you are trying to get get miliseconds, the date format only returns up to the second. Try using the system.environment.tickcount.

Maybe this world is another planet’s Hell.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top