So i got this code, that checks my IPS and returns a message if its online but it was taking long and it wouldnt show the Items found line by line, rather it showed everything at the end of the loop, it loops around 1516 items.
They told me to use a doevents so it can show line by line as the loop its runnin, but doevents makes my CP sloww and when i stop the program in the middle of the process it returns an error that says ARGUMENT OUT OF RANGE EXCEPTION WAS UNHANDLED:Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index..
I think its the doevents thats doing this....
I want to know if theres anyotehr solution rather the the doevents..
heres my code
VB.NET:
Dim hello As String
Dim sum As Integer
DataGridView2.Rows.Clear()
If DataGridView1.Visible = False Then
DataGridView1.Visible = True
Button2.Visible = True
Me.Button1.Enabled = True
DataGridView2.Visible = False
Botonip.Visible = False
End If
Me.Button1.Enabled = False ''i have to disable the button once the program starts because doevents will continue to leave it on while program runs.
Try
For sum = 0 To DataGridView1.Rows.Count - 1
hello = DataGridView1.Rows.Item(sum).Cells.Item(1).Value ''this checks the ip of rows
If My.Computer.Network.Ping(hello, 500) Then ''this will ping the ip address and return true or false
DataGridView1.Rows.Item(sum).Cells.Item(2).Value = "True" '' this checks or not the checkbox for true or false
Try
DataGridView1.Rows.Item(sum).Cells.Item(3).Value = System.Net.Dns.GetHostEntry(hello).HostName ''this gets the host name of a computer
Catch ex As Exception
DataGridView1.Rows.Item(sum).Cells.Item(3).Value = "Error en Host"
End Try
If DataGridView1.Rows.Item(sum).Cells.Item(3).Value = hello Then
Dim Myhostname As String = GetCpname(hello)
Dim hostnewname As String() = Myhostname.Split(" "c, "<"c)
DataGridView1.Rows.Item(sum).Cells.Item(3).Value = (hostnewname(0))
End If
Dim Mymac As String = GetMACAddress(hello)
Dim MyChar As Char() = {"M"c, "A"c, "C"c, "a"c, "d"c, "d"c, "r"c, "e"c, "e"c, "s"c, " "c, "="c}
Dim mynewmac As String = Mymac.TrimStart(MyChar)
DataGridView1.Rows.Item(sum).Cells.Item(4).Value = mynewmac
Else
DataGridView1.Rows.Item(sum).Cells.Item(2).Value = "false"
DataGridView1.Rows.Item(sum).Cells.Item(3).Value = ""
DataGridView1.Rows.Item(sum).Cells.Item(4).Value = ""
End If
My.Application.DoEvents()
Next
Finally
Me.Button1.Enabled = True ''once program end i have to restore the button that enabled the application to check again for IPs online
End Try
End Sub