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

VBA (Excel), peer to peer, one clock?

Status
Not open for further replies.

rudo

Programmer
Jul 3, 2002
72
NL
In a small peer to peer network (computer1 to computer4) I have different VB applications for excel. A unique clock is needed to organize securely tasks on different computers.

Does anyone know code to import system time from computer1 in VB applications of the other computers?

Note: There is a user on computer1, so it would not be a good option to start up Excel on his computer, display time with a worksheet formula and import this time as a string to the other computers each time a time registration is needed...

Thanks in advance for your tips. Greetings from Holland,

Rudo
 
Do you have a dedicated server?


if so use it's time...


-------------------------------------




Option Explicit
'
'
Private Declare Function NetRemoteTOD Lib "Netapi32.dll" ( _
tServer As Any, pBuffer As Long) As Long
'
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 Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
'
Private Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
'
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long
'
Private Type TIME_OF_DAY_INFO
tod_elapsedt As Long
tod_msecs As Long
tod_hours As Long
tod_mins As Long
tod_secs As Long
tod_hunds As Long
tod_timezone As Long
tod_tinterval As Long
tod_day As Long
tod_month As Long
tod_year As Long
tod_weekday As Long
End Type
'
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'
'
Public Function getRemoteTOD(ByVal strServer As String) As Date
'
Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte
'
tServer = strServer & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)
'
If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = DateSerial(tod.tod_year, tod.tod_month, tod.tod_day) + _
TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
getRemoteTOD = result
Else
Err.Raise Number:=vbObjectError + 1001, _
Description:="cannot get remote TOD"
End If
'
End Function




Private Sub GetRemoteTime()
Dim d As Date
'
d = getRemoteTOD("\\your_server_name")
MsgBox d
End Sub

 
ETID,

Thanks for the code, but there is no server. It is just a small peer-to-peer network. If I can't find a simple way, I can still obtain the informations I want by checking the file-properties "File saved" ... time.

Greetings,

rudo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top