Jump to content

progress bar originally by BrewmanNH


Recommended Posts

Hi to all and thanks to BrewnmanNH,

I got the coded script below when Brewman helped someone out. I modified to suit my needs and I thought all was well, but am getting 'array has an incorrect number of subscripts' error. Can someone help

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIEdit.au3>

#region ### START Koda GUI section ### Form=
$Title = "Installing Applications"
$sText = "Preparing..."
$Form1 = GUICreate($Title, 512, 216, -1, -1, -1) ;BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit($sText, 24, 64, 462, 128, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
$Progress1 = GUICtrlCreateProgress(24, 24, 462, 16)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$ms = 1000
Install()
Sleep($ms)

MsgBox(0, $Title, "Installation is complete.")


Func Install()
    $a = 2
    $e = 100 / $a
    Local $aName[2][2] = [["Installing VLC Media Player...", @ScriptDir & "\vlc-2.2.1-win32.exe" & " /L=1034 /S"], _
    ["Applying VLC Media Player Settings...", @ScriptDir & "\VLCMediaPlayer_KScript.vbs"]]

    For $Loop = 1 To $a
          Run($aName[$Loop][1], "", @SW_HIDE)
        $p = $e * $Loop
        GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop - 1][0] & @CRLF, "|")

        GUICtrlSetData($Progress1, $p)
        Sleep(1000)
    Next
EndFunc   ;==>Install

 

Link to comment
Share on other sites

Arrays are 0-based, so they start at 0, instead of 1.

Try this:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIEdit.au3>

#region ### START Koda GUI section ### Form=
$Title = "Installing Applications"
$sText = "Preparing..."
$Form1 = GUICreate($Title, 512, 216, -1, -1, -1) ;BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit($sText, 24, 64, 462, 128, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
$Progress1 = GUICtrlCreateProgress(24, 24, 462, 16)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$ms = 1000
Install()
Sleep($ms)

MsgBox(0, $Title, "Installation is complete.")


Func Install()
    $a = 2
    $e = 100 / $a
    Local $aName[2][2] = [["Installing VLC Media Player...", @ScriptDir & "\vlc-2.2.1-win32.exe" & " /L=1034 /S"], _
    ["Applying VLC Media Player Settings...", @ScriptDir & "\VLCMediaPlayer_KScript.vbs"]]

    For $Loop = 0 To UBound($aName) - 1
          Run($aName[$Loop][1], "", @SW_HIDE)
        $p = $e * $Loop
        GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop][0] & @CRLF, "|")

        GUICtrlSetData($Progress1, $p)
        Sleep(1000)
    Next
EndFunc   ;==>Install

All good? :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Thanks for the reply and a quick one at that. The progress bar does not show up until the pop up comes up saying installation is complete. When the progress bar comes up its around 50%. Don't need a confirmation the installation is complete. I know I can remark that out. I do have a sneaking feeling the vbs file that is supposed to get called didn't get called. Is there any way so it shows [1 of 2] and [2 of 2]. Right now it shows [0 of 2] and [1 of 2]. By the way I did change Run to RunWait

Not sure if this helps, but here is where I found the thread Brewman helped out on:

 

Edited by Briandr
Link to comment
Share on other sites

My pleasure. :)

The progress bar updating to full at the end of the installation is just due to problems with your math.

I'll be on later and will take another look at the finer details if someone does not already.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

What I can after testing your modified code (not Brewman's) is that the progress bar did not reflect the installation time. Another words, say the install of VLC media player would take 30 seconds, the progress bar disappeared after about 5 seconds. The install continued and finished and the second leg of this process the running of the vbscript did not happen. It would stand to reason that GUICtrlCreateProgress handles the progress bar in conjuction with the loop. I just don't know how and what to adjust in the code.

Edited by Briandr
Link to comment
Share on other sites

 

    For $Loop = 0 To UBound($aName) - 1
          Run($aName[$Loop][1], "", @SW_HIDE)
        $p = $e * $Loop
        GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop][0] & @CRLF, "|")

        GUICtrlSetData($Progress1, $p)
        Sleep(1000)
    Next

That loop will take ubound($aName) - 1 seconds to run.  You probably want to run the process, then start your loop and add an If process exists then continueloop.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Thanks. In regards to number of seconds run, would I want to change this: ubound($aName) - 1 to ubound($aName) + 20. Also, still getting getting 'array has an incorrect number of subscripts' error.

 

 

Edited by Briandr
Link to comment
Share on other sites

no, you would not want it to be dependent on time at all by running your loop until the process no longer exists.  A Do....Until ProcessExists() = 0 would probably be more commonplace for a progress, or maybe nested loops so there is not too much editing, something like:

 

For $Loop = 0 To UBound($aName) - 1
          Run($aName[$Loop][1], "", @SW_HIDE)
          
        For $i = 0 to 1  
            $p = $e * $Loop
            GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop][0] & @CRLF, "|")

            GUICtrlSetData($Progress1, $p)
            Sleep(1000)
            If processexists($filename) Then $i -= 1 ; may have to do a string operation to get the name out of the array, or just set it to $filename at the onset
        Next
    Next

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Not sure how far off this, but thanks for being helpful. I set $filename from the onset or so I thought (limited autoit scripting knowledge). It echos (loops out about 12 times) and the progress bar while present does not move left to right as the install continues. 

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#include <GUIEdit.au3>

#region ### START Koda GUI section ### Form=
$Title = "Installing Applications"
$sText = "Preparing..."
$Form1 = GUICreate($Title, 512, 216, -1, -1, -1) ;BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit($sText, 24, 64, 462, 128, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
$Progress1 = GUICtrlCreateProgress(24, 24, 462, 16)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

$ms = 1000
$filename = "vlc-2.2.1-win32.exe"
Install()
Sleep($ms)

MsgBox(0, $Title, "Installation is complete.")


Func Install()
    $a = 1
    $e = 100 / $a
    Local $aName[1][2] = [["Installing VLC Media Player...", @ScriptDir & "\vlc-2.2.1-win32.exe" & " /L=1034 /S"]]

    ;["Applying VLC Media Player Settings...", @ScriptDir & "\VLCMediaPlayer_KScript.vbs"]]

   For $Loop = 0 To UBound($aName) - 1
          Run($aName[$Loop][1], "", @SW_HIDE)

        For $i = 0 to 1
            $p = $e * $Loop
            GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop][0] & @CRLF, "|")
            GUICtrlSetData($Progress1, $p)
            Sleep(1000)
            If processexists($filename) Then $i -= 1 ; may have to do a string operation to get the name out of the array, or just set it to $filename at the onset
    Next
        Next
EndFunc   ;==>Install

 

Link to comment
Share on other sites

I would use a progress bar with the marquee style instead of trying to guess how long it might take to run the installation. Use $PBS_MARQUEE in the style parameter of the GUICtrlCreateProgress function call. This way you can put the progress bar up and just let them know it's working without trying to figure out the timing. If you need a splash screen type of progress bar, you can use the UDF I have linked in my signature to one that I wrote a while ago.

 

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...