prgwkp Posted February 20, 2012 Share Posted February 20, 2012 (edited) Can someone please tell me what is wrong with this loop? Once it hits the "Else" section and "EndIf", it loops back thru and it runs every command down the line, ignoring the IF statements. Should it not reset the IF statement once it loops back up to "Do"? If not, what is a better option? I need this to loop thru 200 hundred times and compare the arrays and follow the IF commands. . Global $SourceLocationArray[200] Global $SecondaryArray[200] $SecondaryArray[0] = "1.PDF" $SecondaryArray[1] = "2.PDF" $SecondaryArray[2] = "3.PDF" $SecondaryArray[3] = "4.PDF" $SecondaryArray[4] = "5.PDF" $SourceLocationArray[0] = "1.PDF" $SourceLocationArray[1] = "2.PDF" $SourceLocationArray[2] = "3.PDF" $SourceLocationArray[3] = "4.PDF" $SourceLocationArray[4] = "5.PDF" $SourceLocationArray[5] = "6.PDF" $z = 0 $Loop = 0 Do If $SecondaryArray[$z] = $SourceLocationArray[$z] Then ;MsgBox(0,"Source and Secondary","Will be deleted from both Source and destination " & $SecondaryArray[$z]) FileDelete("C:ArrayDestination" & $SecondaryArray[$z]) FileDelete("C:ArraySource" & $SecondaryArray[$z]) $z = $z + 1 Else ;MsgBox(0,"Secondary Only","Will only be deleted from Secondary") FileDelete("C:DesktopArrayDestination" & $SecondaryArray[$z]) $z = $z + 1 EndIf $Loop = $Loop + 1 Until $Loop = 200 Edited February 20, 2012 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 20, 2012 Share Posted February 20, 2012 Increment the $z variable after the If loop, not in it. I think.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
prgwkp Posted February 20, 2012 Author Share Posted February 20, 2012 That should not make a difference. I went ahead and tested that to make sure though, same outcome. Link to comment Share on other sites More sharing options...
KaFu Posted February 20, 2012 Share Posted February 20, 2012 For me it looks like it does exactly what I would expect, check the console output. expandcollapse popupGlobal $SourceLocationArray[200] Global $SecondaryArray[200] $SecondaryArray[0] = "1.PDF" $SecondaryArray[1] = "2.PDF" $SecondaryArray[2] = "3.PDF" $SecondaryArray[3] = "4.PDF" $SecondaryArray[4] = "5.PDF" $SourceLocationArray[0] = "1.PDF" $SourceLocationArray[1] = "2.PDF" $SourceLocationArray[2] = "3.PDF" $SourceLocationArray[3] = "4.PDF" $SourceLocationArray[4] = "5.PDF" $SourceLocationArray[5] = "6.PDF" $z = 0 $Loop = 0 Do If $SecondaryArray[$z] = $SourceLocationArray[$z] Then ;MsgBox(0,"Source and Secondary","Will be deleted from both Source and destination " & $SecondaryArray[$z]) ConsoleWrite($z & @tab & $Loop & @tab & "Will be deleted from both Source and destination " & $SecondaryArray[$z] & @crlf) ;FileDelete("C:ArrayDestination" & $SecondaryArray[$z]) ;FileDelete("C:ArraySource" & $SecondaryArray[$z]) $z = $z + 1 Else ;MsgBox(0,"Secondary Only","Will only be deleted from Secondary") ConsoleWrite($z & @tab & $Loop & @tab & "Will only be deleted from Secondary" & @crlf) ;FileDelete("C:DesktopArrayDestination" & $SecondaryArray[$z]) $z = $z + 1 EndIf $Loop = $Loop + 1 Until $Loop = 200 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
BrewManNH Posted February 20, 2012 Share Posted February 20, 2012 A much easier way of accomplishing what you want with only one variable is to use a For...Next loop instead of using $z and $Loop you can do it this way: For $z = 0 To 199 If $SecondaryArray[$z] = $SourceLocationArray[$z] Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SourceLocationArray[$z] = ' & $SourceLocationArray[$z] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ;MsgBox(0,"Source and Secondary","Will be deleted from both Source and destination " & $SecondaryArray[$z]) ;~ FileDelete("C:ArrayDestination" & $SecondaryArray[$z]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SecondaryArray[$z] = ' & $SecondaryArray[$z] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ;~ FileDelete("C:ArraySource" & $SecondaryArray[$z]) ;~ $z = $z + 1 ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $z = ' & $z & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Else ;MsgBox(0,"Secondary Only","Will only be deleted from Secondary") ;~ FileDelete("C:DesktopArrayDestination" & $SecondaryArray[$z]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SecondaryArray[$z] = ' & $SecondaryArray[$z] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ;~ $z = $z + 1 EndIf ;~ $Loop = $Loop + 1 ;~ Until $Loop = 200 Next If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
prgwkp Posted February 20, 2012 Author Share Posted February 20, 2012 (edited) After seeing the console out, I now see that once it the arrays are empty it then goes into the IF statement and the first statement is true at that point and it goes and deletes all contents of both folders. This is because the the array is empty to it deletes all in the directory because it does not specify a file. I though by adding the line of code ... If $SecondaryArray[$z] Or $SourceLocationArray[$z] = "" Then MsgBox(0,"","Exit Loop") ExitLoop EndIf would resolve this, but it did not. Here is the full updated code, what can I do to say if there is a blank array variable in either array to exit loop? expandcollapse popupGlobal $SourceLocationArray[200] Global $SecondaryArray[200] $SecondaryArray[0] = "1.PDF" $SecondaryArray[1] = "2.PDF" $SecondaryArray[2] = "3.PDF" $SecondaryArray[3] = "4.PDF" $SecondaryArray[4] = "5.PDF" $SourceLocationArray[0] = "1.PDF" $SourceLocationArray[1] = "2.PDF" $SourceLocationArray[2] = "3.PDF" $SourceLocationArray[3] = "4.PDF" $SourceLocationArray[4] = "5.PDF" $SourceLocationArray[5] = "6.PDF" $z = 0 $Loop = 0 Do If $SecondaryArray[$z] Or $SourceLocationArray[$z] = "" Then MsgBox(0,"","Exit Loop") ExitLoop EndIf If $SecondaryArray[$z] = $SourceLocationArray[$z] Then MsgBox(0,"Source and Secondary","Will be deleted from both Source and destination " & $SecondaryArray[$z]) FileDelete("C:Documents and SettingsprgwkpDesktopArrayDestination" & $SecondaryArray[$z]) FileDelete("C:Documents and SettingsprgwkpDesktopArraySource" & $SecondaryArray[$z]) ;$z = $z + 1 Else MsgBox(0,"Secondary Only","Will only be deleted from Secondary") FileDelete("C:Documents and SettingsprgwkpDesktopArrayDestination" & $SecondaryArray[$z]) ;$z = $z + 1 EndIf $z = $z + 1 $Loop = $Loop + 1 Until $Loop = 200 Edited February 20, 2012 by Melba23 Added code tags Link to comment Share on other sites More sharing options...
prgwkp Posted February 20, 2012 Author Share Posted February 20, 2012 Thanks, I agree BrewManNH, but that will not solve the problem I am having. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 20, 2012 Moderators Share Posted February 20, 2012 prgwkp,If you post code, please use Code tags - put [autoit] before and [/autoit] after your posted code. I will amend the earlier posts in this thread - you do it from now on - deal? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted February 20, 2012 Share Posted February 20, 2012 Try adding this line just before your first If/Then statement in the loop in the code I gave you: If $SecondaryArray[$z] = "" Or $SourceLocationArray[$z] = "" Then ExitLoop It will exit the loop if either of the array elements are blank. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
prgwkp Posted February 20, 2012 Author Share Posted February 20, 2012 Melba23, I apologize, first time ever posting, I will use the tags you mentioned. BrewManNH, that worked, thank you for your help! Link to comment Share on other sites More sharing options...
KaFu Posted February 20, 2012 Share Posted February 20, 2012 Maybe this is of use to you, thought this is what you're after , check every element of array a against every element of array b. Global $SourceLocationArray[200] Global $SecondaryArray[200] $SecondaryArray[0] = "1.PDF" $SecondaryArray[1] = "2.PDF" $SecondaryArray[2] = "3.PDF" $SecondaryArray[3] = "4.PDF" $SecondaryArray[4] = "5.PDF" $SourceLocationArray[0] = "1.PDF" $SourceLocationArray[1] = "2.PDF" $SourceLocationArray[2] = "3.PDF" $SourceLocationArray[3] = "4.PDF" $SourceLocationArray[4] = "5.PDF" $SourceLocationArray[5] = "6.PDF" ; Use a Buffer Global $sBuffer For $i = 0 To UBound($SourceLocationArray) - 1 $sBuffer &= ";" & $SourceLocationArray[$i] & ";" Next For $i = 0 To UBound($SecondaryArray) - 1 If $SecondaryArray[$i] Then If StringInStr($sBuffer, ";" & $SecondaryArray[$i] & ";") Then ConsoleWrite("Will be deleted from both Source and destination" & @TAB & $SecondaryArray[$i] & @CRLF) Else ConsoleWrite("Will only be deleted from Secondary" & @TAB & $SecondaryArray[$i] & @CRLF) EndIf EndIf Next OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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