Jump to content

add a progress bar to a script


Go to solution Solved by Subz,

Recommended Posts

i have this script that i need a progress bar about

 

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>

$s = FileRead("book.txt")

Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended

Next
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

plz help

Link to post
Share on other sites

This is how I normally write my progress bars:

 

 

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>

$s = FileRead("book.txt")

Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
ProgressOn ( "Starting up", "Loading", "Loading", Default, Default, 18 )
For $i = 0 to UBound($w)-1
    ProgressSet ( ( $i / (UBound ( $w ) - 1) ) * 100, "text to show item being processed", "main text" )
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended

Next
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
ProgressOff ()
; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

 

Edited by MattHiggs
Link to post
Share on other sites
  • Solution

You could use SplashTextOn to display the text as it's being processed, things like FileRead and StringRegExp could take several seconds to complete before the progress even started.  Basic example:

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>

Example()

Func Example()
    Local $sTitle = "Example Project"
    Local $sFilePath = @ScriptDir & "\Example.txt"
    SplashTextOn($sTitle, "Reading : " & $sFilePath, 300, 50)
    Local $s = FileRead($sFilePath)
    ControlSetText($sTitle, "", "Static1", "Processing : " & $sFilePath)
    Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
    _ArrayColInsert($w, 1)
    For $i = 0 to UBound($w)-1
        StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
        $w[$i][1] = @extended
        ControlSetText($sTitle, "", "Static1", $i & " of " & UBound($w)-1)
    Next
    ControlSetText($sTitle, "", "Static1", "Sorting Array")
    _ArraySort($w, 1, 0, 0, 1)
    SplashOff()
    _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
EndFunc   ;==>Example

 

Link to post
Share on other sites
#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>
#include <AutoItConstants.au3>

Example()

Func Example()
$s = FileRead("2.txt")
ProgressOn("word frequency", "Increments every row", "0%", -1, -1, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE))
Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended
   ProgressSet($i, $i & "%")

Next
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
ProgressSet(100, "Done", "Complete")
; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

ProgressOff()
EndFunc   ;==>Example

i almost got it working with a minor bug in percent value

 

how to fix it?

Screenshot_2.png

Link to post
Share on other sites

i tried it again, it works with less content, if there's thousands of words it doesn't show progress it says "not responding" for many minutes

Capture.PNG

 

here's what i have

 

#Include <Array.au3>
#Include <Debug.au3>
#include <Constants.au3>
#include <AutoItConstants.au3>

Example()

Func Example()
$s = FileRead("book.txt")
ProgressOn ( "Word Frequency", "Counting", "Loading", Default, Default, 18 )
Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3)
_ArrayColInsert($w, 1)
For $i = 0 to UBound($w)-1
   ProgressSet (( $i/(UBound($w) - 1)) * 100, "processed", "word frequency" )
   StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0])
   $w[$i][1] = @extended


Next
_ArraySort($w, 1, 0, 0, 1)
_DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)
; _DebugArrayDisplay($w, "Title", "|0:1")
; _DebugArrayDisplay($w, "Title", "|0:1", $ARRAYDISPLAY_NOROW)

ProgressOff()
EndFunc   ;==>Example

 

Edited by vinnyMS
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...