|
-
Aug 11th, 2015, 03:10 AM
#1
Thread Starter
Junior Member
Looping Code, Save time
Hi all.
So here the deal.
I I making a program to monitor the connection state to 54 servers.
The code works perfect but it's rediculously long and if I want to alter it at any point. I have to change it 54 times!
Can someone assist me in looping the script so it does one block of code 54 times (or 55 if we get another server etc)
here are the first two blocks
Code:
Label1.Text = "Checking Store 01: 1st attempt (1000ms)"
ProgressBar1.Value = 1
If My.Computer.Network.Ping("192.168.1.1", 1000) Then
If p01.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 01, connection restablished" & Environment.NewLine)
p01.BackColor = Color.Lime
t01.BackColor = Color.Lime
Else
Label1.Text = "Checking Store 1: 2nd attempt (5000ms)"
If My.Computer.Network.Ping("192.168.1.1", 5000) Then
If p01.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 01, connection restablished" & Environment.NewLine)
p01.BackColor = Color.Lime
t01.BackColor = Color.Lime
Else
Label1.Text = "Checking Store 1: 3rd attempt (10000ms)"
If My.Computer.Network.Ping("192.168.1.1", 10000) Then
If p01.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 01, connection restablished" & Environment.NewLine)
p01.BackColor = Color.Lime
t01.BackColor = Color.Lime
Else
If p01.BackColor = Color.Lime Then Log.AppendText(Now.ToString & " :Store 01, connection dropped" & Environment.NewLine)
p01.BackColor = Color.Red
t01.BackColor = Color.Red
End If
End If
End If
'****************************************************************************************
Label1.Text = "Checking Store 02: 1st attempt (1000ms)"
ProgressBar1.Value = 2
If My.Computer.Network.Ping("192.168.2.1", 1000) Then
If p02.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 02, connection restablished" & Environment.NewLine)
p02.BackColor = Color.Lime
t02.BackColor = Color.Lime
Else
Label1.Text = "Checking Store 2: 2nd attempt (5000ms)"
If My.Computer.Network.Ping("192.168.2.1", 5000) Then
If p02.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 02, connection restablished" & Environment.NewLine)
p02.BackColor = Color.Lime
t02.BackColor = Color.Lime
Else
Label1.Text = "Checking Store 2: 3rd attempt (10000ms)"
If My.Computer.Network.Ping("192.168.2.1", 10000) Then
If p02.BackColor = Color.Red Then Log.AppendText(Now.ToString & " :Store 02, connection restablished" & Environment.NewLine)
p02.BackColor = Color.Lime
t02.BackColor = Color.Lime
Else
If p02.BackColor = Color.Lime Then Log.AppendText(Now.ToString & " :Store 02, connection dropped" & Environment.NewLine)
p02.BackColor = Color.Red
t02.BackColor = Color.Red
End If
End If
End If
'****************************************************************************************
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|