Ok so for a while now ive had a program that pings about 15 computers on my network, but the way i have it is pretty messy, id like to somehow make the code a bit cleaner.
so what i have is something like this
vb Code:
Private Sub Ping() If My.Settings.server1ip <> String.Empty Then Dim MyPing As New System.Net.NetworkInformation.Ping Dim MyPingResult As System.Net.NetworkInformation.PingReply = MyPing.Send(My.Settings.server1ip) If MyPingResult.Status = Net.NetworkInformation.IPStatus.Success Then Me.txtServer1Status.ForeColor = Color.Green Me.txtServer1Status.Text = ("Online") Me.txtServer1Reply.Text = (MyPingResult.RoundtripTime.ToString & " ms") If MyPingResult.RoundtripTime.ToString > 200 Then Me.txtServer1Reply.ForeColor = Color.Red Else If MyPingResult.RoundtripTime.ToString > 100 Then Me.txtServer1Status.ForeColor = Color.Orange End If End If Else Me.txtServer1Status.ForeColor = Color.Red Me.txtServer1Status.Text = ("Failed") End If Else Me.txtServer1Status.Text = ("No IP Entered") End If End Sub
so what i have is i copy that code 10 times and rename each sub to ping1 ping2 ping 3 etc. then i have a button with code like this
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Ping() Ping2() Ping3() Ping4() Ping5() Ping6() Ping7() End Sub
so that runs all my pings... now as you can see its a mess, and im sure its not the best way to go about it. so is there a way i can mold all that into 1 sub? i dont want to ping a range of computers, i want to ping a specific 15-20 ip's.
thanks in advance.




Reply With Quote