cherdeg Posted December 2, 2008 Share Posted December 2, 2008 (edited) #include <Array.au3> Local $a_AllFoundComputers[4] = ["host-00", "host-01", "host-02", "host-03"] Local $a_TmpFoundComputers = $a_AllFoundComputers _ArrayDisplay($a_AllFoundComputers) For $i=0 To UBound($a_AllFoundComputers) - 1 $i_Roundtrip = Ping($a_AllFoundComputers[$i], 20) If $i_Roundtrip = 0 And @error >= 0 Then _ArrayDelete($a_TmpFoundComputers, $i-1) EndIf Next _ArrayDisplay($a_TmpFoundComputers)I'm getting mad!!! Please help me out...given: "host-02" is reachable and online. Normally, I would use the following line to sort out offline hosts from my array: _ArrayDelete($a_TmpFoundComputers, $i). But that doesn't work! For what reason ever "host-01" is the one remaining in "$a_TmpFoundComputers". To get the correct result I have to subtract 1 from "$i". Why???I'm going crazy here...! Edited December 2, 2008 by cherdeg Link to comment Share on other sites More sharing options...
martin Posted December 2, 2008 Share Posted December 2, 2008 #include <Array.au3> Local $a_AllFoundComputers[4] = ["host-00", "host-01", "host-02", "host-03"] Local $a_TmpFoundComputers = $a_AllFoundComputers _ArrayDisplay($a_AllFoundComputers) For $i=0 To UBound($a_AllFoundComputers) - 1 $i_Roundtrip = Ping($a_AllFoundComputers[$i], 20) If $i_Roundtrip = 0 And @error >= 0 Then _ArrayDelete($a_TmpFoundComputers, $i-1) EndIf Next _ArrayDisplay($a_TmpFoundComputers) I'm getting mad!!! Please help me out...given: "host-02" is reachable and online. Normally, I would use the following line to sort out offline hosts from my array: _ArrayDelete($a_TmpFoundComputers, $i). But that doesn't work! For what reason ever "host-01" is the one remaining in "$a_TmpFoundComputers". To get the correct result I have to subtract 1 from "$i". Why??? I'm going crazy here...!You have not really thought about what happens when you remove an element form the array. The problem is that you are counting from 0 to Ubound - 1. You should instead count from Ubound -1 down to 0. The way you are doing it means that when an element is deleted, all the other elements above are shifted down one position. So isay you delete [2] and then delete[3] well you are actually deleting [2] then what was [4] Try this #include <Array.au3> Local $a_AllFoundComputers[4] = ["host-00", "host-01", "host-02", "host-03"] Local $a_TmpFoundComputers = $a_AllFoundComputers _ArrayDisplay($a_AllFoundComputers) For $i= UBound($a_AllFoundComputers) - 1 to 0 step -1 $i_Roundtrip = Ping($a_AllFoundComputers[$i], 20) If $i_Roundtrip = 0 And @error >= 0 Then _ArrayDelete($a_TmpFoundComputers, $i-1) EndIf Next _ArrayDisplay($a_TmpFoundComputers) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
November Posted December 2, 2008 Share Posted December 2, 2008 #include <Array.au3> Local $a_AllFoundComputers[4] = ["host-00", "host-01", "host-02", "host-03"] Local $a_TmpFoundComputers = $a_AllFoundComputers _ArrayDisplay($a_AllFoundComputers) For $i=0 To UBound($a_AllFoundComputers) - 1 $i_Roundtrip = Ping($a_AllFoundComputers[$i], 20) If $i_Roundtrip = 0 And @error >= 0 Then _ArrayDelete($a_TmpFoundComputers, $i-1) EndIf Next _ArrayDisplay($a_TmpFoundComputers) I'm getting mad!!! Please help me out...given: "host-02" is reachable and online. Normally, I would use the following line to sort out offline hosts from my array: _ArrayDelete($a_TmpFoundComputers, $i). But that doesn't work! For what reason ever "host-01" is the one remaining in "$a_TmpFoundComputers". To get the correct result I have to subtract 1 from "$i". Why??? I'm going crazy here...! Hi there m8, I tryed your script and is going well. I changed the hostnames, 2 will ping and the other two dont, i all's good. #include <Array.au3> Local $a_AllFoundComputers[4] = ["127.0.0.1", "localhost", "thor", "mastadonte"] Local $a_TmpFoundComputers = $a_AllFoundComputers _ArrayDisplay($a_AllFoundComputers) For $i=0 To UBound($a_AllFoundComputers) - 1 $i_Roundtrip = Ping($a_AllFoundComputers[$i], 20) If $i_Roundtrip = 0 And @error >= 0 Then ConsoleWrite("Response : " & $i_Roundtrip & " for : " & $a_AllFoundComputers[$i]& @CRLF & "Error : " & @error & @CRLF) _ArrayDelete($a_TmpFoundComputers, $i) Else ConsoleWrite("Response : " & $i_Roundtrip & " for : " & $a_AllFoundComputers[$i]& @CRLF & "Error : " & @error & @CRLF) EndIf Next _ArrayDisplay($a_AllFoundComputers) _ArrayDisplay($a_TmpFoundComputers) Cheers Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
cherdeg Posted December 2, 2008 Author Share Posted December 2, 2008 You have not really thought about what happens when you remove an element form the array.Hi Martin,Yes, you're right. My fault. I thought, copying the array would help me solving this problem - but of course the same happens to the temp-array as well. I'll give your solution a shot and report back soon.Regards, Chris Link to comment Share on other sites More sharing options...
cherdeg Posted December 2, 2008 Author Share Posted December 2, 2008 (edited) Hi there m8,I tryed your script and is going well.I changed the hostnames, 2 will ping and the other two dont, i all's good.Nope, it isn't. Your first two entries reply, the other ones don't, I suppose? Just move the 127.0.0.1 to the third or fourth position and you will see the problem...(but I'm very glad to see that I'm not the only one having missed Martin's advice) Edited December 2, 2008 by cherdeg Link to comment Share on other sites More sharing options...
November Posted December 2, 2008 Share Posted December 2, 2008 Nope, it isn't. Your first two entries reply, the other ones don't, I suppose? Just move the 127.0.0.1 to the third or fourth position and you will see the problem...(but I'm very glad to see that I'm not the only one having missed Martin's advice) I see... Well it worked... badly but it did Cheers and i need to keep my eyes open Old Scriptology Visual Ping 1.8 - Mass Ping Program with export to txt delimited. Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code. Desktop 2 RGB - Pick a color in the desktop and get the RGB code. ShootIT 1.0 - Screen Capture full and partial screen [font="'Arial Black';"]Remember Remember The Fifth of November.[/font] Link to comment Share on other sites More sharing options...
cherdeg Posted December 2, 2008 Author Share Posted December 2, 2008 I see... Well it worked... badly but it did Cheers and i need to keep my eyes open ...and so do I. I'm glad there was a rational solution for my problem, or I'd definitely gone mad...I was scratching my head for about 3 hours about this...but if you visualize it, it's completely clear: a "stack" of items that is checked from top to bottom.Martin: thank you so much - your the guy that made my day! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now