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

Member Avatar for Unhnd_Exception

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?

Servers is the array holding server names,

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

Member Avatar for Unhnd_Exception
'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
commented: A simple effective solution to my problem. +0

Thanks very much Unhnd_Exception, that works a treat :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.