0

Hi All,

I am currently making a server monitoring application that pings the server to check its uplink, so far it creates all the picture boxes and labels for each server, and then pings the server, although I have a picture that I want to change dependant on the result.

Below is the code I am currently using, the problem occurs with the objectname variable which allows dynamic coding, where i get a error, saying that "Public member 'image' on type 'String' not found".

Private Sub Ping()
        Dim i As Integer
        Dim objectName As System.Object
        For i = 1 To count - 1



            Dim pingSender = New Ping()

            'Send the packet with a 1500ms timeout

            Dim reply As PingReply = pingSender.Send(servers(2, i), 1500)

            'Output the reply in the appropriate colour depending on RoundtripTime
            objectName = "pic" + servers(1, i)
            If reply.Status = IPStatus.Success Then

                If (reply.RoundtripTime <= 200) Then
                    objectName. = My.Resources.Online

                ElseIf (reply.RoundtripTime > 200 & reply.RoundtripTime <= 600) Then
                    objectName.Image = My.Resources.Problem
                End If

            Else
                objectName.Image = My.Resources.Offline
            End If
        Next
    End Sub

Can anyone see where I have gone wrong?


Thanks in Advance


Callum

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by CallumP93
Featured Replies
  • [QUOTE=;][/QUOTE] [code] 'Assuming the name of your picbox's 'corresponds to the server name 'and the picturebox's are added to the 'form Dim ObjectName As String = "pic" '+ servers(1,i) Dim p As PictureBox If Me.Controls.ContainsKey(ObjectName) Then p = Me.Controls(ObjectName) Else 'exit sub End If 'p.Image = My.Resources.xxx [/code] Read More

0

You've gone wrong at objectname = "pic" + servers(1,i)

Looks like your wanting to assign a picturebox to objectname but only assigning the name of the picturebox.


What is servers?

0

Servers is the array holding server names,

i need to be able to change the picmysql picture etc without habving to hard code it

1
'Assuming the name of your picbox's 
        'corresponds to the server name
        'and the picturebox's are added to the
        'form

        Dim ObjectName As String = "pic" '+ servers(1,i)

        Dim p As PictureBox

        If Me.Controls.ContainsKey(ObjectName) Then
            p = Me.Controls(ObjectName)
        Else
            'exit sub
        End If

        'p.Image = My.Resources.xxx
Comments
A simple effective solution to my problem.
This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.