Thidian Posted July 27, 2009 Share Posted July 27, 2009 Hello fellow forum members. For the past 3 days, I've been struggling to get a working progressbar that increments x% per line. something like: $read = fileread("file.txt", 0) $count = _filecountline("file.txt") $100percent = ($count/2); Only need half of the lines read, format of the file is currently: Text, new row, BLANK, new row, Text. And from there on, I'm stuck. What I'm trying is to make the progressbar to increment for every 2nd line read by a % (If there's 4 lines in total, 2 is 100% and 1 is 50%, thus making it move 50% at a time to 100%) I've tried EVERY imaginable solution (By searching etc) and now I'm in need of some help. Sincerly, Thidan. Link to comment Share on other sites More sharing options...
enaiman Posted July 27, 2009 Share Posted July 27, 2009 This should work: (not tested code) $count = _FileCountLines("file.txt") $100percent = ($count/2); Only need half of the lines read, format of the file is currently: Text, new row, BLANK, new row, Text. $unit_progress = $100percent/100 For $i = 1 To $count $text_line = FileReadLine("file.txt", $i) If StringStripWS($text_line, 8) = "" Then ContinueLoop ;if the line is blank go to next line (do not set progress) ;or ;If Mod($i, 2) = 0 Then ContinueLoop ;do not set progress if line has an even number ; GUICtrlSetData($your_progress, $i*$unit_progress) Next SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Thidian Posted July 27, 2009 Author Share Posted July 27, 2009 (edited) This should work: (not tested code) $count = _FileCountLines("file.txt") $100percent = ($count/2); Only need half of the lines read, format of the file is currently: Text, new row, BLANK, new row, Text. $unit_progress = $100percent/100 For $i = 1 To $count $text_line = FileReadLine("file.txt", $i) If StringStripWS($text_line, 8) = "" Then ContinueLoop ;if the line is blank go to next line (do not set progress) ;or ;If Mod($i, 2) = 0 Then ContinueLoop ;do not set progress if line has an even number ; GUICtrlSetData($your_progress, $i*$unit_progress) Next Hmm.... Seems like "GUICtrlSetData($your_progress, $i*$unit_progress)" doesn't change anything but if I change "$i*$unit_progress)" to for example "15", it sets the value to 15 like it should. Edit: Got it to work, I think. Going to try it around alittle more. Edit2: Ignore the above statement. Used $i/$unit_progress >.< Edited July 28, 2009 by Thidian Link to comment Share on other sites More sharing options...
Thidian Posted July 28, 2009 Author Share Posted July 28, 2009 Seems like I've edited too much or something, can't edit my post >_< After doing some research. Let's say the file contains 2 lines that I want to use (4 in total). You divide by 100. Sum from that will be 0.02. When the progress is updated, it uses (example value: $i = 1) $i*0.02=1*0.02=0.02=2% of the total 100% of the progress and not the 100% I'm after =/ Going to search for some progress UDF. Link to comment Share on other sites More sharing options...
enaiman Posted July 28, 2009 Share Posted July 28, 2009 lol - what UDF are you after??? Just think a little bit! Have a look at this example: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> Global $lines = 12 Global $unit = 100/($lines/2) Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 511, 114, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Progress1 = GUICtrlCreateProgress(24, 32, 457, 25) $Button1 = GUICtrlCreateButton("Button1", 232, 80, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "Button1Click") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() For $i = 1 To $lines ;$text_line = FileReadLine("file.txt", $i) ;If StringStripWS($text_line, 8) = "" Then ContinueLoop ;if the line is blank go to next line (do not set progress) ;or If Mod($i, 2) = 0 Then ContinueLoop ;do not set progress if line has an even number ; GUICtrlSetData($Progress1, ($i+1)/2*$unit) Sleep(500) Next MsgBox(0, "", "DONE") EndFunc Func Form1Close() Exit EndFunc If you can't get your code to work after this; I'm giving up. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Thidian Posted July 28, 2009 Author Share Posted July 28, 2009 Think I get it now, cheers mate. The thing is, the file I'm reading can have up to 15k lines in it and my brain just froze while trying (Tested the other example you gave me inside my code but it just got all messy) And I just thought there might be a UDF that sets a pbar max to whatever number you wanted to but nevermind >_< Once again cheers <3 Link to comment Share on other sites More sharing options...
DCCD Posted July 28, 2009 Share Posted July 28, 2009 _FileCountLines() Func, Does not work with files > 300Mb [u][font=Arial Black]M[/font]y Blog, AVSS Parts[/u][font=Arial Black]Else[/font][font=Arial Black]L[/font]ibya Linux Users Group Link to comment Share on other sites More sharing options...
nfaustin Posted July 29, 2009 Share Posted July 29, 2009 (edited) Try this... $read = fileread("file.txt", 0) $count = _filecountline("file.txt") $100percent = ($count/2) ---> $100percent = (100 / ($count/2)) ; $100percent variable is your add-ons on Progress bar Edited July 29, 2009 by nfaustin [font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now