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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SystemTime returns 0 4

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi, I am wondering why my SystemTime object returns 0 for hour, min, second, etc. Here is my code

Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
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

...

in some function I have

Debug.Print myTime.wDay & ", " & myTime.wHour & ", " & myTime.wMinute

and I get 0's. what could be the problem? Also, does anyone know how I can get milliseconds as a 11 digit number (I am using it create unique ID)

thanks!!!
 
Thanks for asking, I often wondered if I could get a time increment smaller than a second but was too lazy to look :p. Anyways, try this:

Code:
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
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 Sub Form_Load()
    Dim myTime As SYSTEMTIME
    GetSystemTime myTime 'you were probably missing this?
    Debug.Print myTime.wDay & ", " & myTime.wHour & ", " & myTime.wMinute
End Sub
 
Just because SYSTEMTIME has a wMiiliseconds member do not be fooled into thinking that GetSystemTime has millisecond accuracy.
 
ok, thanks a lot, that missing line made it work... I get milliseconds as a 3 digit number. There is no way to increase presicion? Is there another function that would allow me to do that?


thanks!!!
 
I don't hold out much hope...

There's a school of thought that says "If milliseconds matter to you, what the hell are you doing in VB?"

For creating a Unique ID, have you considered using GUID in SQL_Server?

mmilan

 
>create unique ID

You might want to consider any of the following API calls: UUIDCreate , CoCreateGuid, UUIDCreateSequential

>I don't hold out much hope...

There are a couple of hi res clocks. Firstly the multimedia timers have 1 millisecond resolution, and theQueryPerformanceFrequency/QueryPerformanceCounter API combo will get you even better than that...
 
Thank you for mentioning this method of getting time strongm.

I found a couple decent articles regarding theQueryPerformanceFrequency/QueryPerformanceCounter that I found useful for my future reference.


Wait example:

Elapsed time example:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top