Sign in to follow this  
Followers 0
Willow

Calling a function does not run until the gui window is closed

4 posts in this topic

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

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

1. you don't need the Call("UpdateProgress"); simply specify the function to call, with parameters

CODE
Case $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 by dmob

Share this post


Link to post
Share on other sites

1. you don't need the Call("UpdateProgress"); simply specify the function to call, with parameters

CODE
Case $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.

Thanks for the help, this resolved the problem. I have one more question that I started a new post for.

Willow.

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
Sign in to follow this  
Followers 0