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

DateTime Ticks 1

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
Hi,
is there a way to get something similar to Ticks in VB.

This code is C#:
string tempTicks = DateTime.Now.Ticks.ToString();

thanks!!
 
There are a number of similar ideas that can be used in VB, but it would probably help to know why you need the tick count before being able to advise on the most appropriate.
 
strongm,
thanks
C# app that we have uses that to create a 14 digit unique ID
'string tempTicks = DateTime.Now.Ticks.ToString();
' int startPos = (tempTicks.Length - 13) < 0 ? 14 : tempTicks.Length - 13;
' return "0" + tempTicks.Substring(startPos);
' }

I need to do something like that in VB

thanks!!
 
Option Explicit

Private Declare Function GetFileTime Lib "kernel32" (ByVal hFile As Long, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32" (lpSystemTime As SYSTEMTIME, lpFileTime As FILETIME) As Long
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Private Type FILETIME
dummy As Currency
End Type

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 Command1_Click()
Debug.Print AlmostUniqueID
End Sub

' Only almost unique, because of the actual clock resolution on current platforms is either about 10ms or 15ms
' which means it is possible to get the same value back if we make the calls too close to each other
' Note that this is also true of the Ticks value
Private Function AlmostUniqueID() As String
Dim sysTime As SYSTEMTIME
Dim fTime As FILETIME

GetSystemTime sysTime
SystemTimeToFileTime sysTime, fTime
AlmostUniqueID = Right(String(14, "0") & fTime.dummy, 14)
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top