|
-
Jan 22nd, 2008, 11:44 PM
#1
Thread Starter
Lively Member
[2008] How can i do this
Sorry for the non descriptive title but i dunno how to explain what i wanna do.
basically i have a program that pings my servers at work every minute and displays the reply time and status
heres what it looks like

now my problem is all the fields are static, i have say 14 fields for servers, what id like is to make a selection box to how many im going to have, say 1 or 20 and it will adjust it accordingly.
now heres the code im using (its a mess)
vb Code:
Private Sub btnCheckStatus_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckStatus.Click
strfail = "Failed Ping"
Me.txtserver1Status.Text = "down"
Me.txtserver1Status.ForeColor = Color.Red
Me.server1_responsetime.Text = ("")
If My.Settings.server1_ip <> String.Empty Then
Dim MyPing As New System.Net.NetworkInformation.Ping
Dim MyPingResult As System.Net.NetworkInformation.PingReply = MyPing.Send(My.Settings.server1_ip)
If MyPingResult.Status = Net.NetworkInformation.IPStatus.Success Then
log_pings(Me.server1_responsetime.Text, My.Settings.server1_name)
Me.txtserver1Status.Text = "Up"
Me.server1_responsetime.Text = (MyPingResult.RoundtripTime.ToString & " ms")
Me.txtserver1Status.ForeColor = Color.Lime
Else
log_database(Date.Now.ToShortTimeString, Date.Now.ToShortDateString, My.Settings.server1_name, strfail)
Me.txtserver1Status.Text = "down"
Me.txtserver1Status.ForeColor = Color.Red
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(5000) '5 second display
If My.Settings.server1emailalert = True Then
send_email()
End If
End If
End If
End Sub
i have this code copied and pasted 14 times to run when when the same button is clicked, i just name them Private Sub btnCheckStatus_Click1, 2, 3, 4 etc.
how hard will it be for me to squeeze all this code into 1 sub that runs when the button is clicked and will allow me to change how many servers to display.
thanks in advance.
-
Jan 23rd, 2008, 12:06 AM
#2
Re: [2008] How can i do this
You should create a TableLayoutPanel with the appropriate number of rows and columns, i.e. 1 and 3. Add a Label to each of the cells, leaving the first one blank. Set the TLP's AutoSize property to True. Then you can just add a Label and two TextBoxes for every server you want to test and the TLP will grow automatically.
-
Jan 23rd, 2008, 12:30 AM
#3
Lively Member
Re: [2008] How can i do this
Another option, since the textboxes are apparently for display only, is to replace them with borderless labels. That way, the user won't see anything if the label is empty.
-
Jan 23rd, 2008, 04:16 PM
#4
Thread Starter
Lively Member
Re: [2008] How can i do this
ok so those 2 options can solve my problem on the front page, but what about if i only have 10 servers hard coded in and say i wanna make it possible to ping 20 servers? is there some code i can ise to ping upt ot 20 or even 30 servers without having to hard code each of them in?
-
Jan 23rd, 2008, 07:27 PM
#5
Re: [2008] How can i do this
Whenever you add a "server" you can add it to a List, then each time you want to ping you just loop through the List and ping each one. Using my suggestion you don't even really need a List because you can just loop through the rows of the TLP. At each row you get the server address from the TextBox in the second column and then output the result to the TextBox in the third column.
-
Jan 23rd, 2008, 07:30 PM
#6
Re: [2008] How can i do this
You could also make a user control that encapsulates all the functionality, from actual pinging code, the the UI itself.
Then use the tablelayout like John said, filling it with instances of this user control.
There are many ways to do it.
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
|