Jump to content

Adding up percent to a progress bar...


Recommended Posts

Hello every1!! :)

OK...I have a script that will read a line from a file and then process it...and I want to add 1% to a progress bar each time a line is processed. Here's what I currently have:

Func Play($file)
    GUICtrlSetData($open_play, "Press ESC or F1 to exit...")    ; set new data for the button
    $progressRate = 100/UBound($file, 1)    ; Set progress rate <NOT WORKING>
    GUICtrlSetData($progress, 0)
    For $x = 1 To UBound($file, 1)-1
        Beep($file[$x][0],$file[$x][1], $file[$x][2])       ; Beep
        $newProgress = GUICtrlRead($progress) + $progressRate; Add up the new progress <NOT WORKING>
        GUICtrlSetData($progress, $newProgress)         ; Set the progress <NOT WORKING>
    Next
    GUICtrlSetData($open_play, "Open/Play") ; Reset the initial data for the button
    GUICtrlSetState($open_play, $GUI_ENABLE)    ; Re-enable the button
EndFunc

With that, if the file has more than 100 lines the progress bar will simply not work, and with a file with less than 100 lines, it'll just go up to like 80%!! :lmao:

What am I doing wrong?? I did the same thing to a byte-adding script and it worked perfect!! o:)

Please help!! thanx!! :)

El-Truchahttp://www.truchasoft.tk[url="ftp://tsfc.homeftp.net"]ftp://tsfc.homeftp.net[/url]hotline://tsfc.ath.cx

Link to comment
Share on other sites

  • Developers

What about this way:

Func Play($file)
    GUICtrlSetData($open_play, "Press ESC or F1 to exit...")  ; set new data for the button
    GUICtrlSetData($progress, 0)
    For $x = 1 To UBound($file, 1)-1
        Beep($file[$x][0],$file[$x][1], $file[$x][2])        ; Beep
        GUICtrlSetData($progress, $x/UBound($file, 1) * 100); Set the progress <NOT WORKING>
    Next
    GUICtrlSetData($open_play, "Open/Play")  ; Reset the initial data for the button
    GUICtrlSetState($open_play, $GUI_ENABLE)  ; Re-enable the button
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This is what I always use.

Dim $FileArray
_FileReadToArray(@DesktopDir & "\Test.txt", $FileArray)
If @error Then
   MsgBox(16, "AutoIt Error!", "Could not read file." & @CRLF & "Exiting...")
   EXIT
EndIf

Dim $FilePercent
ProgressOn("AutoIt3 Script", "Processing file...", "0%", -1, -1, 16)

For $i = 1 To $FileArray[0]
   $FilePercent = Round($i / $FileArray[0] * 100)
   ProgressSet($FilePercent, $FilePercent & "%")
   Sleep(100)
Next

ProgressOff()

Func _FileReadToArray( $sFilePath, ByRef $aArray )
 ;==============================================
 ; Local Constant/Variable Declaration Section
 ;==============================================
  Local $hFile
    
  $hFile = FileOpen( $sFilePath, 0 )

  If $hFile = -1 Then
    SetError( 1 )
    Return 0
  EndIf

   $Content = StringStripCR(FileRead( $hFile, FileGetSize( $sFilePath ) ))
  $aArray = StringSplit( $Content, @LF )

  FileClose( $hFile )
  Return 1
EndFunc
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...