Jump to content

Progressbar with file read


Recommended Posts

Hello,

I'm making a program what reads a file and shows the content in a edit control. All i want to do is making a progressbar, so that i can monitor the status of the file reading, because the log files a very big.

The problem is that the progressbar hangs in a loop. I don't understand what i'm doing wrong. I hope someone can help me. I will show the code of the function.

Grtz.

The code:

Func OpenFile()

_GUICtrlEdit_SetText($iMemo2, "")

If FileExists(@ScriptDir & "\copy_logfile.txt") Then FileDelete(@ScriptDir & "\copy_logfile.txt")

$sPath = FileOpenDialog('Open Files', "C:\Temp\logs", 'Logfiles (*.*)')

If @error = 1 Then

MsgBox(16, "Error!", "You haven't open any log file!")

Return

EndIf

GUICtrlSetData($Label4, $sPath)

FileCopy($sPath, @ScriptDir & "\copy_logfile.txt")

$temp_copy = @ScriptDir & "\copy_logfile.txt"

GUICtrlSetFont($iMemo2, 9, 400, 0, "Courier New")

$i = 0

$Total_lines = _FileCountLines($temp_copy)

ProgressOn("Progress Meter", "Increments every second", "0 percent")

While 1

$sMessage2 = FileReadLine($temp_copy, $i)

_GUICtrlEdit_AppendText($iMemo2, $sMessage2)

If $i = @error -1 Then

ExitLoop

Else

$i = $i + 1

ProgressSet( $i, $i & " percent")

EndIf

WEnd

;Next

ProgressSet(100 , "Done", "Complete")

sleep(500)

ProgressOff()

EndFunc :)

Edited by bubke
Link to comment
Share on other sites

Hi, thanks for your suggestion.

@error -1 means that if the end of the file is reached. I've changed it in :

edited on 18:35:

$i = 0

$progressbar = GUICtrlCreateProgress (10,15,200,20,$PBS_SMOOTH)

For $i = 0 To 100

$sMessage2 = FileRead($temp_copy)

GUICtrlSetData ($progressbar,$i)

$i = $i + 1

Next

ProgressOff()

It works, but it's a little bit slow. If someone has an improvement, then I'm glad to hear. :)

Grtz.

Edited by bubke
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...