2008-01-25

Get time of different timezone

Dim theUTCTime As DateTime
    Dim localZone As TimeZone = TimeZone.CurrentTimeZone
    Dim TheZone As Integer = 1
    Const GMTZone As Integer = 1
    Const TOKZone As Integer = 2
    Const ATHZone As Integer = 3


    Private Sub Timer1_Tick( ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Timer1.Tick
        theUTCTime = localZone.ToUniversalTime(TimeString)
        Select Case TheZone
            Case GMTZone
                ‘ Greenwich Mean Time
                TimeBox.Text = theUTCTime.ToShortTimeString
            Case TOKZone
                ‘ Tokyo Time
                theUTCTime = theUTCTime.AddHours(9)
            Case ATHZone
                ‘ Athens Time
                theUTCTime = theUTCTime.AddHours(2)
        End Select
        TimeBox.Text = theUTCTime.ToShortTimeString
    End Sub

2008-01-14

亂數排列

應用: 樸克片洗牌, 亂數排列陣列裏的值
 
Randomize()
   For i As Integer = 0 To UBound(ExamAns)
    Dim j As Integer = Rnd() * UBound(ExamAns)
    Dim tmp As String = ExamAns(i)
    ExamAns(i) = ExamAns(j)
    ExamAns(j) = tmp
   Next

2008-01-11

Get client IP from TCPClient

Dim IsConnected As Boolean = False
   Dim myClient As TcpClient = Listener.AcceptTcpClient
   Do
    IsConnected = myClient.Connected
   Loop Until IsConnected = True
   Dim ipend As Net.IPEndPoint = myClient.Client.RemoteEndPoint
 
   LogMessage(ipend.Address.ToString & " connected")