Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
* Check Time
? "Current Time on Server: " + ttoc(settime("W:\rgb", .T.))
* Set Workstation Time to Server Time
IF NOT settime("W:\rgb") && failed to set
Messagebox("OOPs!")
ENDIF
* Program....: SETTIME.PRG
* Author.....: ** Richard G Bean **
* Date.......: May 10, 2001
* Compiler...: Visual FoxPro 06.00.8961.00 for Windows
* Parameters:
* p_cServerDataPata - Provide a Path to the Data Server where we can write a temp file
* p_lJustGetServerTime - .T. -> just return the server Time, .F. -> Set Workstation to this time
*
*
LPARAMETERS p_cServerDataPata, p_lJustGetServerTime
LOCAL l_tWSCurrent, l_pTimeSet, l_nRetVal, l_nLastError, l_cBuffer
IF PCOUNT() < 2 OR VARTYPE(p_lJustGetServerTime) <> "L"
p_lJustGetServerTime = .F.
ENDIF
LOCAL l_cTempFileName, l_nFileHndl, l_nFound, tod_month, tod_day, tod_year, tod_hours, tod_mins, tod_secs
LOCAL serverdatetime, l_pTimeSet, l_nRetVal, l_nLastError
l_cTempFileName = SYS(2015) && Unique Procedure Name
l_cTempFileName = ADDBS(p_cServerDataPata) + l_cTempFileName + ".$$$"
l_nFileHndl = FCREATE(l_cTempFileName)
IF l_nFileHndl < 0 && Check for error opening file
RETURN .F.
ENDIF
=FCLOSE(l_nFileHndl) && Close file
l_nFound = ADIR(l_aInfo, l_cTempFileName)
IF l_nFound <> 1
RETURN .F.
ENDIF
DELETE FILE (l_cTempFileName)
tod_month = MONTH(l_aInfo[3])
tod_day = DAY(l_aInfo[3])
tod_year = YEAR(l_aInfo[3])
tod_hours = INT(VAL(SUBSTR(l_aInfo[4], 1, 2)))
tod_mins = INT(VAL(SUBSTR(l_aInfo[4], 4, 2)))
tod_secs = INT(VAL(SUBSTR(l_aInfo[4], 7, 2)))
serverdatetime = DATETIME(tod_year, tod_month, tod_day, ;
tod_hours, tod_mins, tod_secs)
IF p_lJustGetServerTime
RETURN serverdatetime
ENDIF
* Set the Local Time and Date
* First check local to see if it's worth changing
l_tWSCurrent = datetime()
IF ABS(serverdatetime - l_tWSCurrent) < 16 && close enough - avoid the overhead
RETURN .T.
ENDIF
l_pTimeSet = "" ;
+ word2str(tod_year);
+ word2str(tod_month);
+ word2str(1);
+ word2str(tod_day);
+ word2str(tod_Hours);
+ word2str(tod_Mins);
+ word2str(tod_Secs);
+ word2str(0)
Declare INTEGER SetLocalTime in kernel32 STRING
l_nRetVal = SetLocalTime(l_pTimeSet)
IF l_nRetVal = 0 && Error
DECLARE INTEGER GetLastError in Kernel32
l_nLastError = GetLastError()
Declare Integer FormatMessage in kernel32 Long, Long, Long, Long, String, Long, Long
#DEFINE FORMAT_MESSAGE_FROM_SYSTEM 0x1000
#DEFINE LANG_NEUTRAL 0x0
l_cBuffer = replicate(chr(0), 201)
= FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ;
l_nLastError, LANG_NEUTRAL, @l_cBuffer, 200, 0)
l_cBuffer = ALLTRIM(STRTRAN(l_cBuffer, chr(0),""))
messagebox(l_cBuffer, 0, "Please Note")
RETURN .F.
ENDIF
* Use SendMessage to tell everybody that we've changed the system time.
DECLARE INTEGER SendMessage IN win32api ;
INTEGER WindowHandle, ;
INTEGER MESSAGE, ;
STRING Param1, ;
STRING Param2
* SendMessage constants.
#DEFINE HWND_BROADCAST 65535
#DEFINE WM_TIMECHANGE 30
* Send the message that the time has changed.
= SendMessage(HWND_BROADCAST, WM_TIMECHANGE, "", "")
RETURN .T.
*************************************************************
FUNCTION word2str
*************************************************************
* passed: integer value
* returns: 2-byte character string (m.longstr) in low-high ASCII format
* example:
* m.wordval = 111
* m.wordstr = word2str(m.wordval)
LPARAMETERS p_nWordval
PRIVATE l_nii, l_cRetval
l_cRetval = ""
FOR l_nii = 0 to 1
l_cRetval = l_cRetval + CHR(p_nWordval % 256)
p_nWordval = int(p_nWordval / 256)
NEXT
RETURN l_cRetval
*!* EOP: SETTIME.PRG