Moderators Melba23 Posted December 30, 2011 Moderators Share Posted December 30, 2011 Dana,Hence my comment about the construct being "an abomination" that "only works by pure luck". Why rely on the AutoIt parser when you can make it unambiguous with parentheses (do not agree that they are necessarily redundant) or by splitting the two statements (much better practice)? Booleans are tricky things and any coding shortcut is a recipe for disaster. Just make the code as simple as possible and there is much more chance of getting it right! M23 jaberwacky 1 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 December 31, 2011 Share Posted December 31, 2011 The problem with the OPs statement is that it should always result in $success being equal to False, as long as the RunWait doesn't error and/or return 0. Because $Folders[$i] is a string that, as long as the folder name isn't a number, is going to result in it being 0 when compared to the exit code of the RunWait. At least that's how I interpreted it. 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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 (edited) Dana, Hence my comment about the construct being "an abomination" that "only works by pure luck". Why rely on the AutoIt parser when you can make it unambiguous with parentheses (do not agree that they are necessarily redundant) or by splitting the two statements (much better practice)? Booleans are tricky things and any coding shortcut is a recipe for disaster. Just make the code as simple as possible and there is much more chance of getting it right! M23 Ok, but if i'm doing this: For $i = 1 to UBound($Folders) -1 If $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE) Then If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then All_File_Delete_Crypt() EndIf FileDelete(@TempDir & "Test.txt") MsgBox(0,"Information","OK") Next Else FileDelete(@TempDir & "Test.txt") MsgBox(0,16,"Error","NO") EndIf Return 1 EndFunc I have N MsgBox for every file checked by CMD, if i'm insert a Return under MsgBox i have 1 messages but only i file processed. Find for me please another solution to this, i'm here to learn, and not create construct being "an abomination" Edited December 31, 2011 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,You post some code that flows logically and I will try and rework it for you. At present that code has so many errors within the For..Next and If..Then...Else structures that it is difficult to see what the logic flow is supposed to be: For $i = 1 To UBound($Folders) - 1 If $Folders[$i] = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE) Then If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then All_File_Delete_Crypt() EndIf FileDelete(@TempDir & "Test.txt") MsgBox(0, "Information", "OK") ;### Tidy Error -> "next" is closing previous "if" on line 2 Next ;### Tidy Error -> "else" is closing previous "for" on line 1 Else FileDelete(@TempDir & "Test.txt") MsgBox(0, 16, "Error", "NO") ;### Tidy Error -> "endif" is closing previous "for" on line 1 EndIf Return 1 ;### Tidy Error: next line creates a negative tablevel. ;### Tidy Error: next line creates a negative tablevel for the line after it. EndFunc ;==>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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 (edited) johnmcloud,You post some code that flows logically and I will try and rework it for you. At present that code has so many errors within the For..Next and If..Then...Else structures that it is difficult to see what the logic flow is supposed to be: The logis is:Array process in the directory the complete path of file, so do this path to cmd likeecho offtest.exe -e -p pathofthefile.txttest.exe -e -p pathofthefile.txttest.exe -e -p pathofthefile.txttest.exe -e -p pathofthefile.txtIf command is right, ( and checkbox is thicked ) good + make a func() + deletetefile a file + msgboxIf command is right, ( and checkbox is NOT thicked ) good + deletetefile a file + msgboxif something goes wrong, bad and deletetefile a file + msgbox Your code don't work, give me error for "Next" statement Edited December 31, 2011 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,Of course "my" code does not work - it is just "your" code after Tidy had a look at the structure and showed the errors! I will try and devise something for you this morning - but do not hold your breath as I have a lot on. 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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 johnmcloud,Of course "my" code does not work - it is just "your" code after Tidy had a look at the structure and showed the errors! I will try and devise something for you this morning - but do not hold your breath as I have a lot on. M23Ok, thanks,P.S My strange code work and don't give me error except many MsgBox ( 4 file processed? 4 MsgBox )But i want to make good coding, so i'll wait, i'll really appreciate you work Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,What return value are you expecting from your RunWait command to decide between "good" and "bad"? We need to know that to construct the conditional statement which follows. 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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 (edited) johnmcloud, What return value are you expecting from your RunWait command to decide between "good" and "bad"? We need to know that to construct the conditional statement which follows. M23 0 = Good I know it's strange, but i'll test it in different script, for autoit and this specific software 0 is not error, other result different from 0 is error. Take a look at this example for single file: $Path = "C:Test.txt" $Pre = "C:Test.exe" $Command = "-e -p" $Test = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & '"' & $Path & '"', @TempDir, @SW_HIDE) If $Test = 1 then MsgBox(16,"Good","Good") Else MsgBox(0,"Error","Error") EndIf The result is MsgBox(0,"Error","Error") $Path = "C:Test.txt" $Pre = "C:CDModule.exe" $Command = "-e -p" $Password = 123 $Test = RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & '"', @TempDir, @SW_HIDE) If $Test = 0 then MsgBox(16,"Good","Good") Else MsgBox(0,"Error","Error") EndIf The result is MsgBox(16,"Good","Good"), so i have to do this script for single file If RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & '"', @TempDir, @SW_HIDE) Then MsgBox(16,"Error","Error") Else MsgBox(16,"Good","Good") So Work=0 NotWork= 1. I'm totally sure the command work becouse the software create a .log file with "success", but for autoit is error so i have I reversed the MsgBox. It's my first case, i never see something like that. Edited December 31, 2011 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,I think this will work for you - it shows just the one MsgBox when all is done and even tells you which elements failed the test: expandcollapse popup; Create a flag $fFlag = "" For $i = 1 To UBound($Folders) - 1 ; Do your cmd bit here and check if it works - you said a return of 0 = good If RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE) = 0 Then ; If it worked then check the checkbox If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then ; Run the function if it is checked All_File_Delete_Crypt() EndIf Else ; Add the error index to the flag if there was a failure $fFlag &= $i & "|" EndIf ; And here we delete the file FileDelete(@TempDir & "Test.txt") Next ; Now we check to see if the flag is still clear If $fFlag = "" Then ; The flag was not amended so all RunWaits ran successfully MsgBox(0, "Information", "OK") Else ; The flag was set so at least one RunWait did not run successfully ; So which ones failed - split the flag into an array $aFailed = StringSplit($fFlag, "|") ; And loop through the array to get the names $sMsg = "The following elements failed:" & @CRLF & @CRLF For $i = 1 To $aFailed[0] - 1 $sMsg &= $Folders[$aFailed[$i]] & @CRLF Next ; And now display them MsgBox(0, "Error", $sMsg) EndIfIf it not quite what you want then let me know and we can tweak it a bit. As to the return value "Work=0 NotWork=1" not matching the AutoIt standard - you can return anything you like from a function just as long as it is clear what each value means. AutoIt usually returns 1 for success, but there is no reason why this should be the case for everything else. 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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 (edited) johnmcloud, I think this will work for you - it shows just the one MsgBox when all is done and even tells you which elements failed the test: If it not quite what you want then let me know and we can tweak it a bit. As to the return value "Work=0 NotWork=1" not matching the AutoIt standard - you can return anything you like from a function just as long as it is clear what each value means. AutoIt usually returns 1 for success, but there is no reason why this should be the case for everything else. M23 Thanks Melba, i'll change a bit because i want the verify for checkbox only if result is =0 $fFlag = "" For $i = 1 To UBound($Folders) - 1 If RunWait(@ComSpec & " /c " & $pre & " " & $command & " " & $Password & " " & '"' & $Path & "" & $Folders[$i] & '"', @TempDir, @SW_HIDE) = 0 Then FileDelete(@TempDir & "Test.txt") Else $fFlag &= $i & "|" EndIf FileDelete(@TempDir & "Test.txt") Next If $fFlag = "" Then If GUICtrlRead($FolderCheckbox) = $GUI_CHECKED Then Function() EndIf MsgBox(0, "Information","OK") Else $aFailed = StringSplit($fFlag, "|") $sMsg = "Error:" & @CRLF & @CRLF For $i = 1 To $aFailed[0] - 1 $sMsg &= $Folders[$aFailed[$i]] & @CRLF Next MsgBox(16, "Error", $sMsg) EndIf Only one think is not clear, the use of: $fFlag = "" $fFlag &= $i & "|" If $fFlag = "" Can you do a simple example for this? Thanks Edited December 31, 2011 by johnmcloud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,We start with the variable as an empty string:$fFlag = ""Each time the test fails, we add the index of the failed item to the string followed by a "|":$fFlag &= $i & "|"When the loop has finished, if nothing failed the string is still empty so we can announce success. If the string has any content, then we will have a list of the index number of the failures - like this:"3|6|8|13|"We can then use StringSplit to turn this into an array and loop through it to announce which elements failed.Clearer now? 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...
johnmcloud Posted December 31, 2011 Author Share Posted December 31, 2011 johnmcloud,We start with the variable as an empty string:$fFlag = ""Each time the test fails, we add the index of the failed item to the string followed by a "|":$fFlag &= $i & "|"When the loop has finished, if nothing failed the string is still empty so we can announce success. If the string has any content, then we will have a list of the index number of the failures - like this:"3|6|8|13|"We can then use StringSplit to turn this into an array and loop through it to announce which elements failed.Clearer now? M23Yes, all clear thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 31, 2011 Moderators Share Posted December 31, 2011 johnmcloud,One last thing - please use the "Reply to this topic" button at the top of the page or the "Reply to this topic" editbox at the bottom. If you use the "Quote" button as you are currently doing the thread becomes double the size and difficult to follow. 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...
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