Willow Posted May 8, 2009 Posted May 8, 2009 I am having some issues with the below code. It is a simple GUI with one button that calls a function to copy files. The _copyprogess function runs fine on its own however when called from the GUI, it will not run until the GUI is closed. What I would like the code to do is to call the function then return back to the GUI window. I searched the help files and the forums however I could not find an answer. Thanks Willow. #include <GUIConstantsEx.au3> #Include <File.au3> ;Allow the use of environmental variables Opt("ExpandEnvStrings", 1) Dialogbox() Func dialogbox() Local $Button_1, $Button_2, $Button_3, $msg GUICreate("Backup Tool") ; will create a dialog box that when displayed is centered ;Set the background colour GUISetBkColor(0xE0FFFF) Opt("GUICoordMode", 2) $Button_1 = GUICtrlCreateButton("Run backup", 10, 30, 100) GUISetState() ; display an dialog box with 1 button ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 call ("_copyProgress") ; display a file progress bar while the files copy EndSelect WEnd EndFunc ;==>Dialogbox ;Copy with Progressbar _copyProgress ("%datadir%\", 'C:\backups\', '*.txt') Func _copyProgress($From_dir, $Dest_dir, $filter = '*.*') Local $count = 0, $dir = "" $FileList = _FileListToArray($From_dir, $filter, 0) If(Not IsArray($FileList)) And(@error = 1) Then SetError(-1) ProgressOn("Copy", "Files :", "0 files") For $i = 1 To UBound($FileList) - 1 If FileGetAttrib($FileList[$i]) = "D" Then $dir = "\*.*" If FileCopy($From_dir & "\" & $FileList[$i] & $dir, $Dest_dir & "\", 9) Then $count += 1 ProgressSet($count * 100 / $FileList[0], _ "From: " & $From_dir & "\" & @LF & "To: " & $Dest_dir & "\" & @LF & $FileList[$i], _ StringFormat('%05.2f', Round(($count * 100 / $FileList[0]), 2)) & " % " & @TAB & $count & "/" & $FileList[0] & " Done") EndIf Sleep(100); to see what happens Next ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() Return 1 EndFunc ;==>_copyProgress
computergroove Posted May 8, 2009 Posted May 8, 2009 http://www.autoitscript.com/autoit3/docs/functions.htmLook at winactive and winactivate Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html
dmob Posted May 8, 2009 Posted May 8, 2009 (edited) 1. you don't need the Call("UpdateProgress"); simply specify the function to call, with parameters CODECase $msg = $Button_1 _copyProgress("%datadir%\", 'C:\backups\', '*.txt') ; display a file progress bar while the files copy 2. You are calling the function (successfully) after you exit the while loop (which you do by closing the GUI), which is why it only runs after you close the GUI. The first call to the function won't run coz you are not passing the required parameters. 3. Use code tags to enclose your code. Edited May 8, 2009 by dmob
Willow Posted May 8, 2009 Author Posted May 8, 2009 1. you don't need the Call("UpdateProgress"); simply specify the function to call, with parameters CODECase $msg = $Button_1 _copyProgress("%datadir%\", 'C:\backups\', '*.txt') ; display a file progress bar while the files copy2. You are calling the function (successfully) after you exit the while loop (which you do by closing the GUI), which is why it only runs after you close the GUI. The first call to the function won't run coz you are not passing the required parameters.3. Use code tags to enclose your code.Thanks for the help, this resolved the problem. I have one more question that I started a new post for.Willow.
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