时间同步 错误的数组或者数组超出界限 错误 已解决
本帖最后由 tzz365 于 2011-1-6 15:03 编辑时间同步 错误的数组或者数组超出界限 错误 已解决 谢谢(chenronting ) 在线等。。 请高手帮解答下 我这里成功, 如果提示数组的话,楼主要在数组里找找, 而我这里大概看了一下, 可能是时间没有得到而引起的数组错误,而你这里好像也没有对时间没有正确的得到时做出反应,所以才会出错。 楼主能缩进下代码么?,楼主能把包含的文件补齐么?#include <Misc.au3>
#include <Date.au3>
#include <Array.au3>
Opt("WinTitleMatchMode", 2);标题的任意子串皆可匹配
Opt("GUICloseOnESC", 0);在按下 ESC 时不退出
;~ MsgBox(64, "时间同步中...完成后自动退出!", 3)
If _Singleton(@ScriptName, 1) = 0 Then
MsgBox(16, "警告", "该程序已经运行,禁止重复运行!", 5)
Exit
EndIf
$_Now_date = _GetSrv_Date()
MsgBox(0, 0, $_Now_date)
$_Now_Splt = StringSplit($_Now_date, " ")
$NowData = StringSplit($_Now_Splt, "-")
$NowTime = StringSplit($_Now_Splt, ":")
;~ _SetDate($NowData, $NowData, $NowData)
;~ _SetTime($NowTime, $NowTime, $NowTime)
_ArrayDisplay($_Now_Splt)
_ArrayDisplay($NowTime)
Func _GetSrv_Date()
Local $_Srvlist = ["time-nw.nist.gov", _
"time-a.nist.gov", _
"time-b.nist.gov", _
"time-a.timefreq.bldrdoc.gov", _
"time-b.timefreq.bldrdoc.gov", _
"time-c.timefreq.bldrdoc.gov", _
"utcnist.colorado.edu", _
"time.nist.gov", _
"nist1.datum.com", _
"nist1.dc.glassey.com", _
"nist1.ny.glassey.com", _
"nist1.sj.glassey.com", _
"nist1.aol-ca.truetime.com", _
"nist1.aol-va.truetime.com"]
UDPStartup()
Local $_Time_Srv
For $x = 0 To UBound($_Srvlist) - 1
$_Time_Srv = $_Srvlist[$x]
Local $Socket = UDPOpen(TCPNameToIP($_Time_Srv), 123)
If @error <> 0 Then ContinueLoop
$Status = UDPSend($Socket, MakePacket())
If $Status = 0 Then ContinueLoop
Local $Data = "", $i = 0
While $Data = ""
$i += 1
$Data = UDPRecv($Socket, 100)
If $i = 5 Then ContinueLoop (2)
Sleep(88)
WEnd
UDPCloseSocket($Socket)
UDPShutdown()
ExitLoop
Next
If $Data = "" Then Return 0
$Data = UnsignedHexToDec(StringMid($Data, 83, 8))
$Data = _DateTimeFormat(_DateAdd("s", $Data, "1900/01/01 08:00:00"), 0)
Return $Data
EndFunc ;==>_GetSrv_Date
Func MakePacket()
Local $P, $D = "1b0e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
While $D
$P &= Chr(Dec(StringLeft($D, 2)))
$D = StringTrimLeft($D, 2)
WEnd
Return $P
EndFunc ;==>MakePacket
Func UnsignedHexToDec($_Data)
Return Dec(StringTrimRight($_Data, 1)) * 16 + Dec(StringRight($_Data, 1))
EndFunc ;==>UnsignedHexToD在不行的机子上调式几次找找原因 回复 4# tryhi
谢谢我试下 感谢楼主分享,学习一下
页:
[1]