Sign in to follow this  
Followers 0
El-Trucha

Adding up percent to a progress bar...

4 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Weird...why do I think I already posted an answer here??

Well, 'newayz...thanx both of u it worked!! o:):lmao:


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

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