31290 Posted October 5, 2015 Posted October 5, 2015 Hi everyone, I'm currently writing a script that will execute some Robocopy batches among what has been ticked by the Technician.The script is divided in two files (the main & the functions) but the thing is that I have to write multiple lines for all controls, as you can see in the functions file.1- Is there a way to shorten this?2- To avoid writing bunch of lines to check whether checkboxes are checked and to lunch appropriate bat, is there also a way to go quicker when clicking on the submit button? (will be implemented in the SubmitCopyChoice() Function)Thanks guys for all the help you can offer Robocopy.au3 Robocopy_Functions.au3 ~~~ Doom Shall Never Die, Only The Players ~~~
jguinch Posted October 5, 2015 Posted October 5, 2015 You need to use an array and a loop, look :; declaring the global variables at the beginning of the script is a good practice Global $aCheckBox = [ "Contacts Folder Only", "Desktop Folder Only", "Downloads Folder Only", "Favorites Folder Only", "My Documents Folder Only", "My Music Folder Only", "My Pictures Folder Only", "My Videos Folder Only", "Searches Folder Only", "Sticky Notes Only", "SAP Logon INI Only", "SAP Logon INI Only"] Global $aCheckBoxIDs[ UBound($aCheckBox) ] ; -------------------------------------------------------------------------------- ; [...] For $i = 0 To UBound($aCheckBox) - 1 $aCheckBoxIDs[$i] = GUICtrlCreateCheckbox($aCheckBox[$i], 5, 270 + $i * 10 * 2, 300) Nextand to change to the state in the different functions, another loop :For $i = 0 To UBound($aCheckBox) - 1 $aCheckBoxIDs[$i] = GUICtrlSetState($aCheckBox[$i], $GUI_UNCHECKED + $GUI_ENABLE) Next Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
31290 Posted October 5, 2015 Author Posted October 5, 2015 jguinch, Thanks for your answers, that's a good point. But, the trick is that for example, is the tech only checks (for example) My Documents + My Videos + Sticky Notes, how's possible for the script to know what to execute of checkboxes do not have "names"?Here's my function after submitting:Func SubmitCopyChoice() ; Global $s_RobocopyOptions = "/R:15 /W:3" If _IsChecked($chk_Contacts) Then $s_Source = $s_Drive & "Users\" & @Username & "\Contacts" $s_Dest = @UserProfileDir & "\Contacts" RunWait(@ComSpec & ' /k robocopy.exe "' & $s_Source & '" "' & $s_Dest & ' ' & $s_RobocopyOptions, @SystemDir) EndIf EndFuncI think I may have no other choices than creating my robocopy job for each checkbox with some if and elseif... At least you have another idea ^^ ~~~ Doom Shall Never Die, Only The Players ~~~
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