System.Text.Encoding.Default.GetBytes(varstring).Length
Dim dest = {{0,0},{0,1},{1,0},{1,1}}
array.GetUpperBound(0)
System.Net.Dns.GetHostEntry(strHostName).AddressList(0).ToString
For i As Integer = 0 To 3
Dim lbl As New Label
lbl.Text = i & " my world"
lbl.Width = 50
lbl.Left = 40 * i
Me.Controls.Add(lbl)
Next
Imports System.Net
Imports System.Net.NetworkInformation
Imports System.Threading
Public Class Form1
Dim dests = {
{"210.71.71.8", "新莊高中web"}, {"cloud.ntpc.edu.tw", "二代公文"}, {"www.ntpc.edu.tw", "教育局"}, {"www.ntu.edu.tw", "台大"}, {"tw.yahoo.com", "Yahoo"}, {"google.com", "Google"}, {"www.facebook.com", "facebook"}
}
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
ToolStripStatusLabel1.Text = Now.ToString
For i As Integer = 0 To dests.GetUpperBound(0)
Dim lbltitle As New Label
lbltitle.AutoSize = True
lbltitle.Text = dests(i, 1)
If i > 24 Then
lbltitle.Location = New Point(340, 50 + 15 * (i - 25))
Else
lbltitle.Location = New Point(70, 50 + 15 * i)
End If
Me.Controls.Add(lbltitle)
Dim lbl As New Label
lbl.Name = "lbl" & i
lbl.ForeColor = Color.Green
If i > 24 Then
lbl.Location = New Point(275, 50 + 15 * (i - 25))
Else
lbl.Location = New Point(10, 50 + 15 * i)
End If
lbl.AutoSize = True
Me.Controls.Add(lbl)
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Control.CheckForIllegalCrossThreadCalls = False
ToolStripStatusLabel1.Text = Now.ToString
For i = 0 To dests.GetUpperBound(0)
Dim pingobj As kkbike
Dim th As Thread
Controls("lbl" & i).ForeColor = Color.Blue
Controls("lbl" & i).text = "wait..."
pingobj = New kkbike
pingobj.dest = dests(i, 0)
pingobj.lbl = Controls("lbl" & i)
th = New Thread(AddressOf pingobj.meow)
th.Start()
Next
End Sub
Class kkbike
Public kkping As New Ping
Public dest As String
Public lbl As New Label
Sub meow()
lbl.ForeColor = Color.Blue
lbl.Text = "probing..."
Dim pr As PingReply = kkping.Send(dest)
lbl.ForeColor = Color.Red
Select Case pr.Status.ToString
Case "Success"
lbl.ForeColor = Color.Green
lbl.Text = "暢通" & pr.RoundtripTime & "ms"
Case "TimedOut"
lbl.Text = "逾時"
Case "DestinationHostUnreachable"
lbl.Text = "主機離線"
Case "BadDestination"
lbl.Text = "位址錯誤"
Case Else
lbl.Text = pr.Status.ToString
End Select
End Sub
End Class