hello, We are upgrading to 4.3 but now we get a error bitwise shifting in Visual Basic to get the time from a NTP time server. This is old code and always worked in 4.2
Dim lIntPart As Long = 0 Dim lFractPart As Long = 0
For i As Integer = 0 To 3 lIntPart = (lIntPart << 8) Or ntpData(bOffsetTransmitTime + i) Next For i As Integer = 4 To 7 lFractPart = (lFractPart << 8) Or ntpData(bOffsetTransmitTime + i) Next
Error 1 Type 'System.Nullable(Of )' is not defined. (The error is under the << 8)
Does anyone knows why and also there is a buildin function in the SDK 4.3 for calling the time server.
How can we call this function?
Public Shared Function GetNetworkTime() As DateTime Dim ep As New IPEndPoint(Dns.GetHostEntry("time-a.nist.gov").AddressList(0), 123) Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) s.Connect(ep) Dim ntpData As Byte() = New Byte(47) {} ' RFC 2030 ntpData(0) = &H1b For i As Integer = 1 To 47 ntpData(i) = 0 Next s.Send(ntpData) s.Receive(ntpData) Dim offsetTransmitTime As Byte = 40 Dim intpart As ULong = 0 Dim fractpart As ULong = 0 For i As Integer = 0 To 3 intpart = 256 * intpart + ntpData(offsetTransmitTime + i) Next For i As Integer = 4 To 7 fractpart = 256 * fractpart + ntpData(offsetTransmitTime + i) Next Dim milliseconds As ULong = (intpart * 1000 + (fractpart * 1000) / &H100000000L) s.Close() Dim timeSpan__1 As TimeSpan = TimeSpan.FromTicks(CLng(milliseconds) * TimeSpan.TicksPerMillisecond) Dim dateTime As New DateTime(1900, 1, 1) dateTime += timeSpan__1 Dim offsetAmount As TimeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime) Dim networkDateTime As DateTime = (dateTime + offsetAmount) Debug.Print(networkDateTime.ToString()) Return networkDateTimeEnd Function
Supra.
- JerseyTechGuy likes this