Sign in to follow this  
Followers 0
wehr

ProgressOn help

12 posts in this topic

I created a GUI. This GUI contains a Combo box. Now if u select 'item1' and click 'button1' it runs another procress then on 'item2'. As this process runs in the background i want a visual like a progress bar to make the user see that something is going.

But to do this i read in another thread that the 'run(process)' command has to be in a string. For progressbar to get the process-id.

i.e:

ProgressOn("test", "test")
        $PID1 = Run("\\Server\netlogon\kix32.exe \\Server\netlogon\vpnscript.kix","", @SW_HIDE)
        While $PID1
        Sleep ( 1000 )

        ProgressSet($PID1)

        $PID1 = ProcessExists($PID1)
        Wend

        
        ProgressOff()

But my Button needs an 'IF' and 'Then'

i.e:

Case $Button1
                If $read = "item1" Then run('process1.exe')
                If $read = "item2" Then run('process2.exe')
                MsgBox(4096, "OK", "Übertragung abgeschlossen")

The problem is i cant write the string behind my 'Then'. (If $read = "item1" Then $PID1)

So how to combine these two correctly?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

A way of doing this would be something like this:

Func _MarqueeGUI($MsgText = "Building the library, please stand by")
    Global $Form2 = GUICreate("", 290, 160, -1, -1, BitOR($WS_DLGFRAME, $WS_POPUP))
    GUISetBkColor(0x00080FF, $Form2)
    Local $PBMarquee = GUICtrlCreateProgress(20, 130, 250, 15, BitOR($PBS_SMOOTH, $PBS_MARQUEE))
    Local $hPBMarquee = GUICtrlGetHandle($PBMarquee)
    _SendMessage($hPBMarquee, $PBM_SETMARQUEE, True, 20) ; final parameter is update time in ms
    GUICtrlCreateLabel($MsgText, 20, 20, 250, 90)
    GUICtrlSetFont(-1, 14, 400, Default, "Comic Sans MS")
    GUICtrlSetColor(-1, 0x0FFFC19)
    GUISetState()
EndFunc

What this does is it creates a GUI, with a Progressbar control that uses the $PBS_MARQUEE parameter. It has no title bar or sysmenu, this example that I took from my media player also has a customizable text label that you can use to change the text whenever you call the function or you can leave that part out.

Your method wouldn't work very well because you're using the ProgressSet to set the progress bar with the PID, that's not going to work.

Edited by BrewManNH

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 Gude
How 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

Share this post


Link to post
Share on other sites

Thanks this Progressbar works way better.

Now how do i make it show while my process is running.

Here's what my 'run' looks like:

Case $Button1
                If $read = "Altdorf" Then Run ('sync1.exe')
                If $read = "Feucht" Then Run ('sync2.exe')

I want the progressbar to show whily 'sync1.exe' or 'sync2.exe' is running.

Share this post


Link to post
Share on other sites

I ran Into a similar problem trying to make a 'syncing app', and i just gave up on it now i can go back and have a look at it again :graduated:


[center]First Ever Script/App[/center][center]Simple Battery Meter[/center]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I re-worked my script a little bit. Now i get a progressbar to show while my sync1.exe is running. This progressbar stays empty. I can't find anything on how to make a little dot jump from left to right, like in these windows anymations. Currently my script looks like this:

Case $Button1
            ProgressOn("", "test")
                If $read = "item1" Then $AC1 = Run ('Sync1.exe')
                 While $AC1
                    Sleep ( 1000 )
                    ProgressSet($AC1)
                    $AC1 = ProcessExists($AC1)
                Wend
                If $read = "item2" Then $FC1 = Run ('Sync2.exe')
                 While $FC1
                    Sleep ( 1000 )
                    ProgressSet($FC1)
                    $FC1 = ProcessExists($FC1)
                Wend
            ProgressOff()

EDIT: sorry somehow i forgot BrewManNH's post. His script does exactly that :graduated:

Edited by wehr

Share this post


Link to post
Share on other sites

So, by now i mastered my progressbar issues. But i came up with a new problem:

When the second gui with the progressbar closes (GUIdelete) then i cant use and buttons on my first gui, but the minimise button.

Here's my whole script:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <SendMessage.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Optik Schweiger", 283, 160, 192, 143)
$Label1 = GUICtrlCreateLabel("Datenbank auswählen:", 16, 16, 249, 17)
$Combo1 = GUICtrlCreateCombo("", 16, 40, 249, 25, $CBS_DROPDOWNLIST)
$Combo2 = GUICtrlSetData($Combo1, "Altdorf|Feucht", "Altdorf")
$Button1 = GUICtrlCreateButton("Daten auf Server übertragen", 16, 70, 249, 35,  $WS_GROUP)
$Button2 = GUICtrlCreateButton("OPTIMAWIN starten", 16, 115, 249, 35, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$MsgText = "Dateien werden auf den Server geladen."
Global $Form2 = GUICreate("", 290, 80, -1, -1, BitOR($WS_DLGFRAME, $WS_POPUP))
Local $PBMarquee = GUICtrlCreateProgress(20, 50, 250, 15, $PBS_MARQUEE, $PBS_SMOOTH)
Local $hPBMarquee = GUICtrlGetHandle($PBMarquee)
_SendMessage($hPBMarquee, $PBM_SETMARQUEE, True, 20) ; final parameter is update time in ms
GUICtrlCreateLabel($MsgText, 20, 20, 250, 90)
GUISetState(@SW_HIDE)


While 1
    $nMsg = GUIGetMsg()
    $read = GUICtrlRead($combo1)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
                If $read = "Altdorf" Then $AC1 = Run ('C:\OPTIMAWIN\sync\FTPSync AC1 /INCREMENTAL /QUIET')
                GUISetState(@SW_SHOW, $Form2)
                    While $AC1
                        If Not ProcessExists ('FTPSync.exe') Then GUIDelete ($Form2)
                    WEnd

                If $read = "Feucht" Then $FC1 = Run ('C:\OPTIMAWIN\sync\FTPSync FC1 /INCREMENTAL /QUIET')
                GUISetState(@SW_SHOW, $Form2)
                    While $FC1
                        If Not ProcessExists ('FTPSync.exe') Then GUIDelete ($Form2)
                    WEnd
        Case $Button2
                If $read = "Altdorf" Then RunWait ('C:\OPTIMAWIN\sync\FTPSync AC2 /INCREMENTAL')
                If $read = "Feucht" Then RunWait ('C:\OPTIMAWIN\sync\FTPSync FC2 /INCREMENTAL')
            Run ('C:\OPTIMAWIN\OPTIMA.exe')



    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Your script is stuck inside the While $AC1($FC1) loops because you have set the value of them to the PID of the running process and never change the value of $AC1 or $FC1. Just because the program ends doesn't mean that the variables assigned the PID of them will change, you have to change the value yourself when you delete the GUI Form2. Something like this:

While $AC1
                        If Not ProcessExists ('FTPSync.exe') Then 
                            GUIDelete ($Form2)
                            $AC1 = 0
                        Endif
                    WEnd

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 Gude
How 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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

with an $AC1 = 0 the 2nd gui (progressbar) won't show up anymore

and exitloop will close my first 'while 1' --> close both guis

Edited by wehr

Share this post


Link to post
Share on other sites

With GUIDelete($Form2) your progressbar won't show up anymore either, so I fail to see the problem. Also, exitloop would work as well, but you don't have any in your code. What your code does is this.

1. You press $Button1

2. If $read = "Altdorf" Then you set $AC1 to the PID returned by this command Run ('C:\OPTIMAWIN\sync\FTPSync AC1 /INCREMENTAL /QUIET')

3. You show your progress bar gui ( GUISetState(@SW_SHOW, $Form2) )

4. Now as long as $AC1 is greater than 0 you are stuck in this loop

While $AC1
    If Not ProcessExists ('FTPSync.exe') Then GUIDelete ($Form2)
WEnd

In this case, $AC1 will NEVER be equal to zero because you set it to the PID of the program in step 2. As soon as the FTPSync.exe program exits, your code deletes $Form2, but is stuck in the While...Wend loop forever because you have no exit code. The code I gave you will exit the loop so that it will continue to the next functions. All I did was add the escape route for your endless loop, if you don't want $Form2 deleted, then don't use GUIDelete. Is this clear?


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 Gude
How 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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I'm sorry I had a misstake in my post as i was in a hurry.

The problem when i use your exact code

While $AC1
                        If Not ProcessExists ('FTPSync.exe') Then
                        GUIDelete ($Form2)
                        $AC1 = 0
                        EndIf
                    WEnd

is that both guis will close, but i need to keep gui1 and close the one with the progressbar only.

Edited by wehr

Share this post


Link to post
Share on other sites

I just ran your script, I used Notepad instead of the one you used, and it didn't delete the main GUI for me.


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 Gude
How 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

Share this post


Link to post
Share on other sites

Now i figuered it out.

All i needed to do is declare my variables $AC1 and $FC1 earlier :graduated:

You brought me on the right track, thanks for your help.

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