Need Help on "Looping a Statement"

jlkf3

New member
Joined
Jun 26, 2009
Messages
2
Programming Experience
Beginner
Hey All,

I am new to VB.NET and to this forum so i apologise in advanced if i have posted this in the wrong section or if i do not use the correct terms. :)

I am creating a simple program to show if "Servers,switches...etc" are currently up by showing me a green box or down by showing me a red box.
I am trying to loop the following code below every 30 seconds. Problem is that there are several of these statements which i want to do the same.
Any help would be amaze please because im really struggling.

The following code:


Private Sub PictureBox11_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox11.BackColorChanged
If My.Computer.Network.Ping("192.168.0.20", 1000) Then
PictureBox11.BackColor = Color.LimeGreen
Else
PictureBox11.BackColor = Color.Red
End If

End Sub




Thanks




Jamie
 
If they all follow this simple logic you can make a sub and pass parameters for which controls to update:

VB.NET:
Private Sub IsWorking(ByVal pb As PictureBox)
If My.Computer.Network.Ping("192.168.0.20", 1000) Then
pb.BackColor = Color.LimeGreen
Else
pb.BackColor = Color.Red
End If
With some small changes you can also pass the IP and port into this as well, so now you only have 1 line of code per control to check.
VB.NET:
'usage
IsWorking(PictureBox1)
This code should be in the timer.tick event - set at 30 sec.
If all you have is a color change, a label would work for this. It seems like a waste to use a pictureBox - that doesn't matter it's your choice.
 
Thanks!!

That works great cheers!!

Thanks for the promt reply :)

I can now continue to destroy it even more



Jamie
 
Back
Top