473,320 Members | 1,978 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,320 software developers and data experts.

Help, get system time with milliseconds without Timer control

jeffbroodwar
118 100+
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a method.... the timer gets stuck along with the process, meaning it always returns .01 millisecond...... timer hangs with my pc..... i need to get the system time (with milliseconds) before and after calling the webservice then compute for the difference..... PLEASE HELP ME GUYS THIS THING'S IMPORTANT TO ME !! Thanx a lot !!!!!
Feb 20 '07 #1
8 43963
hariharanmca
1,977 1GB
please help me get the system's time (with milliseconds) i need it to calculate the Soap request and response time in my SOAP project. i tried to use timer but the problem is, whenever i'm invoking a method.... the timer gets stuck along with the process, meaning it always returns .01 millisecond...... timer hangs with my pc..... i need to get the system time (with milliseconds) before and after calling the webservice then compute for the difference..... PLEASE HELP ME GUYS THIS THING'S IMPORTANT TO ME !! Thanx a lot !!!!!

use Format(Now, "HH:mm:ss:ms")
Feb 20 '07 #2
hariharanmca
1,977 1GB
use Format(Now, "HH:mm:ss:ms")
sorry, the above post is worng
Feb 20 '07 #3
jeffbroodwar
118 100+
Solved....
'Declarations :
-----------------------------------------------------------------------------------------------------------
Option Explicit

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib "kernel32" _
(lpSystemTime As SYSTEMTIME)
------------------------------------------------------------------------------------------------------------

'Function :
------------------------------------------------------------------------------------------------------------
Public Function TimeToMillisecond() As String
Dim sAns As String
Dim typTime As SYSTEMTIME

On Error Resume Next
GetSystemTime typTime
sAns = Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & _
":" & typTime.wMilliseconds
TimeToMillisecond = sAns
End Function
Feb 20 '07 #4
jeffbroodwar
118 100+
guess so.... but why? i mean it goes with vb's format function right? why will it be wrong???... hmm... can you test the code that i've posted? perhaps you can help me decide what's the correct one.... and please explain to me why your post is wrong. i tested it, it's obviously wrong but what made it wrong? thanx....
Feb 20 '07 #5
hariharanmca
1,977 1GB
guess so.... but why? i mean it goes with vb's format function right? why will it be wrong???... hmm... can you test the code that i've posted? perhaps you can help me decide what's the correct one.... and please explain to me why your post is wrong. i tested it, it's obviously wrong but what made it wrong? thanx....
no, i told the post which i had post is wrong
Feb 20 '07 #6
mayhem
1
use Format(Now, "HH:mm:ss:ms")

Format(Now, "HH:mm:ss:ms")

is incorrect..... for some reason the ms is not reconised by visual basic...
I've not had time to look into it, but do simple test

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. MsgBox Format(Now, "HH:mm:ss:ms")
  3. End Sub
you will see the last 3 digits are actully seconds.....
my is "3" then the current seconds digit(s)

the API GetSytemTime Works best for current system time.... API's are always preffered
Mar 13 '07 #7
Hope this is what you wanted:
Expand|Select|Wrap|Line Numbers
  1. Public Sub DoWork()
  2.      Dim startDt as Date = Now()
  3.  
  4.      ' Do you work here
  5.  
  6.      Dim endDt as Date = Now()
  7.  
  8.      Dim tm as long = DateDiffMs(startDt, endDt)
  9.  
  10.   End Sub
  11.  
  12.  
  13.   Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
  14.     Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
  15.     If (endDt.Millisecond - startDt.Millisecond) < 0 Then
  16.       ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
  17.     Else
  18.       ms += (endDt.Millisecond - startDt.Millisecond)
  19.     End If
  20.     Return ms
  21.   End Function
  22.  
Cheers!
Mar 13 '07 #8
Hope this is what you wanted:
Expand|Select|Wrap|Line Numbers
  1. Public Sub DoWork()
  2.      Dim startDt as Date = Now()
  3.      ' Do you work here
  4.      Dim endDt as Date = Now()
  5.      Dim tm as long = DateDiffMs(startDt, endDt)
  6. End Sub
  7.  
  8. Public Shared Function DateDiffMs(ByVal startDt As Date, ByVal endDt As Date) As Long
  9.     Dim ms As Long = DateDiff(DateInterval.Second, startDt, endDt) * 1000
  10.     If (endDt.Millisecond - startDt.Millisecond) < 0 Then
  11.       ms += 1000 - (startDt.Millisecond - endDt.Millisecond)
  12.     Else
  13.       ms += (endDt.Millisecond - startDt.Millisecond)
  14.     End If
  15.     Return ms
  16.   End Function
  17.  
This actually works. I have been looking for a solution to this sort of problem for some time. Funny that I never came across the "Date.Millisecond" bit, it was there all the time...

Thanks very much.
Mar 14 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: curious | last post by:
I am new to VB.NET and I need help in using timer control. Here is the scenario. I have 3 labels (label 1, label2, label 3), and a start button, all vertically aligned on the form. Using a...
4
by: William Bub | last post by:
Is there an accurate way to create a "stopwatch" good to 1/10 of a second? I'm not sure if I should use the timer control, or some way to access the computer timer. I found the following site...
3
by: David | last post by:
Hi There! I'm using Timer control to record how long my application perform certain tasks. However, apparently Timer control is not doing its' job (i.e. Not firing Tick event) while my...
10
by: Partho Choudhury | last post by:
Hi all: I need to add a snippet which access the system time (upto atleast milliseconds) using ANSI std. C++. I cannot use MFC and Win32 APIs in my program for now for various reasons. Is there...
8
by: marcus | last post by:
Is their a method in c++ or c that gives me the system time in milliseconds or higher resolution? I need it to be platform independent. Today I use timeGetTime which is windows specific. thanks
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
1
by: abhishek007p | last post by:
HI, i am using visual web developer for .net 2.0. does .NET 2.0 comes with a timer control, i was unable to find it in the IDE, where is it ? thanks, Abhishek
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
16
by: neelsfer | last post by:
I need to add milliseconds to this finishtime of race !!! = Format(Now(), "General Date") Start code for race also in milliseconds !!! = Format(Now(), "General Date") I will then subtract it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.