lonewolf217 Posted May 28, 2008 Share Posted May 28, 2008 Forgive the title, but i wasn't sure how to explain my problem simply. Basically I have an object containing a list of many items. I am parsing it like for $item in $object ;do something ;if some condition matches, delete item next the problem that i am having with this is probably a fairly obvious one, but the solution escapes me at the moment. It seems that when I delete an item in the list, it will shift the rest of the items in the $object up on position, so when the Next condition is hit, it is actually skipping over one object to get to the next one in the list. for example $object is an array of numbers [1,2,3,4,5,6,7,8,9,10] in my oversimplified code for $item in $object if $item == 2 then delete $item next the way this seems to work is that it will process $item == 2, then delete "2". then the next number it will process is actually 4 Is this actually the way it is behaving or could I have another bug in my code? Link to comment Share on other sites More sharing options...
zorphnog Posted May 28, 2008 Share Posted May 28, 2008 Depends on what kind of object you're using. If its just an array, then you can use a For..To loop instead like so: For $i=0 To Ubound($aMyarray)-1 If $aMyarray[$i] = 2 Then _ArrayDelete($aMyarray, $i) $i -= 1 EndIf Next Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 28, 2008 Author Share Posted May 28, 2008 (edited) unfortunetly the size of the array is dynamic, and I suppose that im not actually using an array at all, I am using an object with a lot of members the jist of what I am doing is processing an Exchange Mailbox, and the object I am working on is the list of all messages in the folder for each folder/subfolder I process each message and check for a certain message class, if it exists I delete the message What I am seeing in my code right now is that if I have multiple of the same message class in a row it is skipping them I had tried hard coding the value of the count for each folder but that got really messy and I was hoping to avoid it Edited May 28, 2008 by lonewolf217 Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 28, 2008 Author Share Posted May 28, 2008 is there a way that I can get the numeric value of the position in the object I am in ? perhaps then i can lower the value by 1 when i delete a message Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted May 28, 2008 Share Posted May 28, 2008 To do it simpler than how it is working out now, instead of deleting them with this run, just append a list of the names of the messages to delete, preferably to an array. Then, loop through the array, deleting matching messages. Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 29, 2008 Author Share Posted May 29, 2008 (edited) Ive tried the latest suggestion by saving a list of entry ids in an array and then going back and trying to load and delete them later but it isn't working out yet so I am back to the original problem. here is a code snippet of one of my functions if someone can take a look and possibly let me know my mistake CODE Func processFolders($folders) for $folder in $folders If $folder.Items.count <> 0 Then for $message in $folder.Items If $message.MessageClass == "IPM.Note.Stub" Then $message.Delete EndIf Next EndIf If $folder.Folders.count <> 0 Then processFolders($folder.Folders) EndIf Next EndFunc I am using the Redemption libraries for this code. $folder is the folder object, $Folder.Items is an object containing all the messages in the folder. I am running this over and over and cannot figure out why it is skipping messages. If i have 10 messages in my Inbox that apply to the MessageClass rule, for some reason only 5 of them are getting deleted. Any help is appreciated. Edit: sorry about the code snippet formatting, can't figure out how to get the indentation to work Edited May 29, 2008 by lonewolf217 Link to comment Share on other sites More sharing options...
zorphnog Posted May 29, 2008 Share Posted May 29, 2008 Try this: #include <Array.au3> Func processFolders($folders) Local $aDeleteFolders[1] = [0] for $folder in $folders If $folder.Items.count <> 0 Then for $message in $folder.Items If $message.MessageClass == "IPM.Note.Stub" Then _ArrayAdd($aDeleteFolders, $message) $aDeleteFolders[0] += 1 EndIf Next EndIf For $i=1 To $aDeleteFolders[0] For $message In $folder.Items If $message = $aDeleteFolders[$i] Then $message.Delete ExitLoop EndIf Next Next ReDim $aDeleteFolders[1] $aDeleteFolders[0] = 0 If $folder.Folders.count <> 0 Then processFolders($folder.Folders) EndIf Next EndFunc Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 29, 2008 Author Share Posted May 29, 2008 I finally found some information on google and it does seem that since i am modifying the number of items in the object it will screw up the count. Once i changed my for loop to this for $i = $folder.Items.count To 1 Step -1 it works just fine. Thanks for the help though! Link to comment Share on other sites More sharing options...
JRowe Posted May 29, 2008 Share Posted May 29, 2008 Check out the _Array UDF, in the UDF help file in your main AutoIt folder. That should give you all the functionality you need. [center]However, like ninjas, cyber warriors operate in silence.AutoIt Chat Engine (+Chatbot) , Link Grammar for AutoIt , Simple Speech RecognitionArtificial Neural Networks UDF , Bayesian Networks UDF , Pattern Matching UDFTransparent PNG GUI Elements , Au3Irrlicht 2Advanced Mouse Events MonitorGrammar Database GeneratorTransitions & Tweening UDFPoker Hand Evaluator[/center] 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