I use vb.net 2008 to build an application. I have a form with 50 textboxes containing the ip address of the remote device, if the ping device is good then the background color of the textbox is green, otherwise red. I use the If function as follows:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.Network.Ping(TextBox1.Text) Then
TextBox1.BackColor = Color.Green
Else
TextBox1.BackColor = Color.Red
End If
If My.Computer.Network.Ping(TextBox2.Text) Then
TextBox2.BackColor = Color.Green
Else
TextBox2.BackColor = Color.Red
End If
.
.’ The if functions of the Textbox3 to the Textbox49
.
If My.Computer.Network.Ping(TextBox50.Text) Then
TextBox50.BackColor = Color.Green
Else
TextBox50.BackColor = Color.Red
End If
End Sub
End Class
For 50 textboxes, I have to use 50 If functions as this makes the code very long, can you help me to shorten code with For ... Next loop. Thank you for your help.