Results 1 to 6 of 6

Thread: [2008] How can i do this

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    120

    [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:
    1. Private Sub btnCheckStatus_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckStatus.Click
    2.         strfail = "Failed Ping"
    3.         Me.txtserver1Status.Text = "down"
    4.         Me.txtserver1Status.ForeColor = Color.Red
    5.         Me.server1_responsetime.Text = ("")
    6.         If My.Settings.server1_ip <> String.Empty Then
    7.             Dim MyPing As New System.Net.NetworkInformation.Ping
    8.             Dim MyPingResult As System.Net.NetworkInformation.PingReply = MyPing.Send(My.Settings.server1_ip)
    9.             If MyPingResult.Status = Net.NetworkInformation.IPStatus.Success Then
    10.                 log_pings(Me.server1_responsetime.Text, My.Settings.server1_name)
    11.                 Me.txtserver1Status.Text = "Up"
    12.                 Me.server1_responsetime.Text = (MyPingResult.RoundtripTime.ToString & " ms")
    13.                 Me.txtserver1Status.ForeColor = Color.Lime
    14.             Else
    15.                 log_database(Date.Now.ToShortTimeString, Date.Now.ToShortDateString, My.Settings.server1_name, strfail)
    16.                 Me.txtserver1Status.Text = "down"
    17.                 Me.txtserver1Status.ForeColor = Color.Red
    18.                 NotifyIcon1.Visible = True
    19.                 NotifyIcon1.ShowBalloonTip(5000) '5 second display
    20.                 If My.Settings.server1emailalert = True Then
    21.                     send_email()
    22.                 End If
    23.             End If
    24.         End If
    25.     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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Lively Member Kenbuddy's Avatar
    Join Date
    Jul 2002
    Location
    Cypress, TX
    Posts
    96

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2008
    Posts
    120

    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?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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
  •  



Click Here to Expand Forum to Full Width