maestro1024 Posted April 7, 2008 Posted April 7, 2008 (edited) Hello, I am trying to see if a new process started which works most of the time. But sometimes there is an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded." I suspect a new process started and caused an issue here but I am not sure (am I using autoit arrays incorrectly?). Anyone see an issue with this? CODE; check to see if list of running processes are different Func TestForChangedProcesses() $currentProcesses=ProcessList() For $i=1 To $currentProcesses[0][0]-1 If Not($currentProcesses[$i][0] == $list[$i][0]) Then ; check to see if saved processes are different LogToFile("Application changed " & $currentProcesses[$i][0]) $list=$currentProcesses ; because processes changed set new list to be the one to test against EndIf next EndFunc Edited April 7, 2008 by maestro1024
DarkMatter Posted April 7, 2008 Posted April 7, 2008 Hello, I am trying to see if a new process started which works most of the time. But sometimes there is an error "Array variable has incorrect number of subscripts or subscript dimension range exceeded." I suspect a new process started and caused an issue here but I am not sure (am I using autoit arrays incorrectly?). Anyone see an issue with this? CODE; check to see if list of running processes are different Func TestForChangedProcesses() $currentProcesses=ProcessList() For $i=1 To $currentProcesses[0][0]-1 If Not($currentProcesses[$i][0] == $list[$i][0]) Then ; check to see if saved processes are different LogToFile("Application changed " & $currentProcesses[$i][0]) $list=$currentProcesses ; because processes changed set new list to be the one to test against EndIf next EndFunc Which line is the error happening on? [sub]Quantum mechanics: The dreams stuff is made of[/sub]
weaponx Posted April 7, 2008 Posted April 7, 2008 (edited) The answer is obvious. If the first snapshot of the processlist contains 20 processes and the second ($currentProcesses) contains 21 you will get an error trying to access the 21st element in the first array.See here for a bettter solution:http://www.autoitscript.com/forum/index.ph...&hl=ListTwo Edited April 7, 2008 by weaponx
maestro1024 Posted April 7, 2008 Author Posted April 7, 2008 Thanks But I am not sure I see the difference. Where in this code are you checking or how do you know you are not out of bounds? CODE;Store current processlist "state" $ListOne = ProcessList () While 1 $ListTwo = ProcessList () ;Verify each process exists in original state, if not, KILL IT!!!!!!!!!!!!!!!! For $X = 1 to $ListTwo[0][0] $found = false ;Comparing by PID, because danwilli would prefer it For $Y = 1 to $ListOne[0][0] If $ListOne[$Y][1] = $ListTwo[$X][1] Then $found = true ExitLoop EndIf Next If $found = false Then MsgBox(0,"","New process found: " & $ListTwo[$X][0]) someFunction() EndIf Next ;Check every 3 seconds Sleep (3000) WEnd Func someFunction() MsgBox(0,"","A new process was opened") EndFunc
weaponx Posted April 7, 2008 Posted April 7, 2008 In your code you are comparing every element like this: For $i=1 To $currentProcesses[0][0]-1 If Not($currentProcesses[$i][0] == $list[$i][0]) This assumes both arrays have the same number of elements. My script loops through all elements in the second snapshot one at a time. For $X = 1 to $ListTwo[0][0] Then for each of those elements I search every element in the first array: For $Y = 1 to $ListOne[0][0] This means the sizes are independent of each other.
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