31290

Actions among checked checkboxes.

3 posts in this topic

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 ~~~

Share this post


Link to post
Share on other sites



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)
Next

and 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

Share this post


Link to post
Share on other sites

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
EndFunc

I 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 ~~~

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • harvester2001
      By harvester2001
      Hi I need your help
      I need download backup from 200 remote pc. I calculate that I can download 20 backups in one time. I need to create loop, take localizations from txt file and start 20 downloads in one time (i want use ShellExecute and robocopy), after finish one from running 20 take another localizations from txt file until localizations finish. And I need trigger if is 7:00 pause script. I hope you know what I mean
      Many thanks for help, sorry for my english.
      This is what I got:
      #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <Date.au3> Local $targets = @ScriptDir& "\targets.txt" Local $log_name = "\autoit.log" MsgBox($MB_SYSTEMMODAL, "", "start copy", 1) Example() Func Example() If Not FileExists($targets) Then MsgBox($MB_SYSTEMMODAL, "", "The file targets.txt - doesn't exist!") Exit EndIf FileOpen($targets, 0) Global $arr[1000] ReDim $arr[_FileCountLines($targets)+1] For $i = 1 to _FileCountLines($targets) $line = FileReadLine($targets, $i) $arr[$i] = $line ; Check if is online Local $iPing = Ping($arr[$i], 250) If $iPing Then ; ONLINE $rc = FileCopy("\\"&$arr[$i]&"\e$\backup\", @ScriptDir&"\downloads\"&$arr[$i]&"\", $FC_CREATEPATH) If $rc = 0 Then _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE error") Else _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" ONLINE done") EndIf Else ;OFFLINE _FileWriteLog(@ScriptDir & $log_name, $arr[$i]&" OFFLINE") EndIf Next EndFunc ;==>Example MsgBox($MB_SYSTEMMODAL, "", "Finish downloads backups") Exit  
    • 31290
      By 31290
      Hi everyone
      Hope you're doing great.
      Well, I'm writing a script that allows our Service Desk to clean several temp folder as a first diagnostic. 
      Indeed, the agent in charge of the issue will have to choose what to clean (web browsers temp folders, some windows one etc...)
      I added a progress bar to see the current state of the script but if I select more than one checkbox, it seems that the counting is not done properly and is directly filled at 100% (when at leat 2 boxes are checked) and I don"t get the final message saying that all is done, especially for if the last box is checked.
      But if I launch the process with only one checkbox checked,it's working...
      I've enclosed the au3 files for you because posting them in this post would be... unreadable lol. So you can maybe do some tests as well.
      I'm pretty sure the code can be optimized (a lot  ) and that there is a much better way to achieve what I want the script to be.
      Maybe can someone can give me a hand over here.
      Thanks in advance.
      31290
      SEE_Delete_Temp.au3
      SEE_Delete_Temp_Functions.au3
    • wakillon
      By wakillon
      TinyBackupBox : Do a Backup of folders you want to a local/external drive/directory by using Robocopy.

      A Big Thank to Yashield for TVExplorer.au3 and WinApiEx.au3

      Includes needed : >TVExplorer.au3 and >WinApiEx.au3



      * Left Treeview :

      Check all folders Checkboxes you want to backup.
      Hold Shift key when clicking a first child Checkbox will check all other child Checkboxes.
      A right click on a parent item will uncheck all his child Checkboxes.

      * Right Treeview :

      A left click for select Backup Directory.
      A right click menu on an item for create a new sub-folder which you can give the name you want.
      This new sub-folder will be created and added as child item of the item you have right clicked.

      * Start Button :

      A Click on Start Button will start backup normally.
      Hold Shift key when clicking it will start backup on Idle Mode.
      Idle Mode is used for start or resume backup after a period of user inactivity (that you can set by tray menu)
      and will pause current backup if not idle.

      * Stop Button :

      A click on Stop Button will Pause backup, and any changes will affect the backup when resume it.
      You can resume a current backup by Re-clicking Start Button.
      Hold Shift key when clicking Stop Button will totally Cancel current backup.
      In Idle mode Stop Button is inactive until you Hold Shift key and click for Cancel current backup.

      * Refresh Button :

      A Click will refresh both treeviews and set them to the previous selections you have done.
      Hold Shift key when clicking it will refresh both treeview and set them to the root.

      * Tray Menu :

      By Default Robocopy copy only new files,
      so i add the possibility to
      _ delete previous existing dir.
      _ delete destination files and dirs that no longer exists in source.
      _ Preserve all Attributes.
      _ Show Robocopy Console window.
      _ Set Idle Time Delay.
      _ Open Backup Dir.

      Update of 2011-12-21
      Previous downloads : 103
       
      source and executable are available in the Download Section

      minimalist but handy !
      Hope you like it !

      And do not forget to create backup periodically !
    • Tsiyoshi
      By Tsiyoshi
      Hello,
      I am trying to add the following parameters to Robocopy embedded in an the Autoit script below: /S /COPY:DT /R:4 /LOG+:"C:Script.log"
      Any suggestions how to add it? 
      Thanks in advance!
      RunWait(@ComSpec & ' /k ' & 'robocopy.exe "' & $SR1 & '" "' & $DS1 & '" ' & $PLC, @SystemDir)
    • ThomasQ
      By ThomasQ
      Hi All!

      I got a bit of a problem. I need to check some checkboxes on a site, wich I can't seem to do (using _IEFormElementCheckboxSelect & _IEAction). I can't even seem to get back the value of the checkboxes. (using _IEFormElementGetValue).

      Since I can't get the info I need straight from the Page Source, I use _IETagNameAllGetCollection, and then sift my way through the mess it returns!
      So far I have been succesfull in finding and manipulating buttons, textarea's, some tables, and dropdown select boxes on the site. All of them using the _IEFormElementGett & Set Value function.

      Through using $oElements = _IETagNameAllGetCollection($oIE), a For $oElement In $oElements / Next loop, and then checking the atrributes of $oElement, using $oElement.tagname, $oElement.id, $oElement.classname, $oElement.innertext & $oElement.Innerhtml.

      Thanks to this I located on of the checkboxes them self (I think).. TAG nr 165.. This is wat it looks like when the checkbox is checked:


      This is Unchecked:


      Notice there is no attribute set to CHECKED, and that it's not even a UNCHECKED or something when it's unchecked on the page. It is not using "value=", so that's probably the reason the _IEFormElementGett & Set Value don't work. Also, after checking a freshly loaded page, abouy 8 TAG objects, wich seem to have something to do with that checkbox, get ID's, wich they previously didn't have.. Does anybody have any idea how I can manipulate those darn Checkboxes? How should I use the _IEFormElementCheckboxSelect on this checkbox? Is there any other way to check/uncheck a checkbox?? Many Thanks in advance!!