Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to syncronize a network ?
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00366440
Message ID:
00366967
Views:
13
>>I was thinking to run a program in background which wrote the system time in a
>>file, so that the other machines could read it and upgrade their time
>>through it.
>>Do u think it could work ?
>
>There's almost no chance of getting it this way, because the time written in the file is static. The easiest thing to do is to have the local system create a temporary file on the server and immediately read it's creation time - the timestamp for the file uses the server machine's time, so you adjust the time on the local workstation to match the server's time.

To go along with what Ed said, after you retrieve the file creatioin datetime from the server machine (using ADIR(), it would be columns 3 and 4), you can use the WinAPI that sets the time. This is supported under Win9X.
=adir(lafile,"myfile.txt")
declare integer SetLocalTime in kernel32 STRING@
lcsystemtime = space(0)
lnyear = year(lafile(1,3))
lnmonth = month(lafile(1,3))
lnday = day(lafile(1,3))
lndayofweek = dow(lafile(1,3))
* parse the character string in column 4 for the time components
lnhour = val(left(lafile(1,4),at(":",lafile(1,4))-1))
lnminute = val(substr(lafile(1,4),at(":",lafile(1,4))+1,(rat(":",lafile(1,4))-1) - at(":",lafile(1,4))))
lnsecond = val(substr(lafile(1,4),rat(":",lafile(1,4))+1))
lcsystemtime = NumtoWord(lnyear)+NumtoWord(lnmonth)+NumtoWord(lndayofweek)+NumtoWord(lnday)+ ;
   NumtoWord(lnhour)+NumtoWord(lnminute)+NumtoWord(lnsecond)+NumtoWord(0)
nres = SetLocalTime(@lcsystemtime)
return

function NumtoWord
lparameter tnNum
lcresult = chr(0)+chr(0)
if tnNum < (2^15 - 1) then
	lcresult = chr(mod(tnNum,256))+chr(int(tnNum/256))
else
	* not a valid number for a WORD value
endif
return lcresult
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform