AllSystemGo Posted June 4, 2008 Share Posted June 4, 2008 (edited) How can I make this work?? For $x = 1 to $aRecords[0] If $x = $aRecords[0] Then ExitLoop If StringInStr($aRecords[$x], $NomWin) Then _ArrayDelete($aRecords, $x) $aRecords[0] = $aRecords[0] - 1 ElseIf StringInStr($aRecords[$x], $MAC) Then $aRecords[$x] = $MAC & " = " & $NomWin $found = True EndIf Next I get this error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Probably because I'm deleting something from the array. How can I fix this?? EDIT: Is this a good way to fix it: If $x = _ArrayMaxIndex($aRecords, 1, 1) Then ExitLoop EDIT2: NVM I think I found, I don't know if it's the good way to do it but I added a If $x = $aRecords[0] Then ExitLoop. I updated the code Cheers Edited June 4, 2008 by AllSystemGo Link to comment Share on other sites More sharing options...
Danny35d Posted June 4, 2008 Share Posted June 4, 2008 Give it a try... $x = 1 While 1 If $x = $aRecords[0] Then ExitLoop If StringInStr($aRecords[$x], $NomWin) Then _ArrayDelete($aRecords, $x) $aRecords[0] = UBound($aRecords) - 1 $x = 0 ElseIf StringInStr($aRecords[$x], $MAC) Then $aRecords[$x] = $MAC & " = " & $NomWin $found = True EndIf $x += 1 Wend AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Valuater Posted June 4, 2008 Share Posted June 4, 2008 IF I am correct... _ArrayDelete($aRecords, $x) $aRecords[0] = $aRecords[0] - 1 The second line is automatically done inside the _ArrayDelete() function Open the include and read the function info ??? 8) Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 4, 2008 Share Posted June 4, 2008 IF I am correct... _ArrayDelete($aRecords, $x) $aRecords[0] = $aRecords[0] - 1 The second line is automatically done inside the _ArrayDelete() function No, I don't think it is. There is no parameter to tell the function if [0] is significant or not, and no basis for assumptions on that. Your script would have to include the second line to do the update of [0], and if so, it should probably be done with $aRecords[0] = Ubound($aRecords) - 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AllSystemGo Posted June 4, 2008 Author Share Posted June 4, 2008 Thank you for all the help, I already tried that but the thing is if I'm not mistaken the For doesn't update his parameters all the time cause he's stuck with let say For $x=1 to 700 even if I update the variable of the 700 to 699 it doens't change anything. Unless I didn't do it right. Correct me if I'm wrong. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 4, 2008 Share Posted June 4, 2008 How can I make this work?? For $x = 1 to $aRecords[0] If $x = $aRecords[0] Then ExitLoop If StringInStr($aRecords[$x], $NomWin) Then _ArrayDelete($aRecords, $x) $aRecords[0] = $aRecords[0] - 1 ElseIf StringInStr($aRecords[$x], $MAC) Then $aRecords[$x] = $MAC & " = " & $NomWin $found = True EndIf Next I get this error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Probably because I'm deleting something from the array. How can I fix this?? EDIT: Is this a good way to fix it: If $x = _ArrayMaxIndex($aRecords, 1, 1) Then ExitLoop EDIT2: NVM I think I found, I don't know if it's the good way to do it but I added a If $x = $aRecords[0] Then ExitLoop. I updated the code Cheers A better way to handle this is walk the array backwards, because deletions will not change the index of other elements when going in reverse: For $x = UBound($aRecords) - 1 To 1 Step -1 If StringInStr($aRecords[$x], $NomWin) Then _ArrayDelete($aRecords, $x) ElseIf StringInStr($aRecords[$x], $MAC) Then $aRecords[$x] = $MAC & " = " & $NomWin $found = True EndIf Next $aRecords[0] = UBound($aRecords) - 1; Update the new count in [0] Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AllSystemGo Posted June 4, 2008 Author Share Posted June 4, 2008 A better way to handle this is walk the array backwards, because deletions will not change the index of other elements when going in reverse: For $x = UBound($aRecords) - 1 To 1 Step -1 If StringInStr($aRecords[$x], $NomWin) Then _ArrayDelete($aRecords, $x) ElseIf StringInStr($aRecords[$x], $MAC) Then $aRecords[$x] = $MAC & " = " & $NomWin $found = True EndIf Next $aRecords[0] = UBound($aRecords) - 1; Update the new count in [0] Worked like a charm. Thank you everyone for the help. 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