Jump to content
Sign in to follow this  
tempman

Progress bar in For loop

Recommended Posts

tempman

Hi,

I want to put Progress bar in For loop

#include <File.au3>

$message = "Open Log file..."

$PATH = FileOpenDialog($message, @WorkingDir & "\", "Log (*.log)", 1 + 4 )
If @error Then Exit

$search = InputBox("Search", "What to serch for", "")

$FILE = FileOpen($PATH, 0)

For $INDEX = 1 To _FileCountLines($PATH)
$LINE = FileReadLine($FILE,$INDEX)
$FIND = StringInStr($LINE,$search)
If Not @error And $FIND <> 0 Then MsgBox(48,"Found!",$LINE)
Next

FileClose($FILE)

MsgBox(64, "Search", "Finished!")

Exit

Heed help, cheers!!!

Share this post


Link to post
Share on other sites
water

And your question is?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

where to to put Progress bar in code to script work properly?

Share this post


Link to post
Share on other sites
water

Check functions ProgressSet, ProgressOn and ProgressOff in the help file. The example scripts there show you what to do.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

I already done that, but since file size is larger than 500kb the progress bar doesn't work correctly

Share this post


Link to post
Share on other sites
water

Can you post the code you have (including the failing progressbar)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

#include <File.au3>

$message = "Open Log file..."

$PATH = FileOpenDialog($message, @WorkingDir & "\", "Log (*.log)", 1 + 4 )
If @error Then Exit

$search = InputBox("Search", "What to serch for", "")

$Form          =  GUICreate("GUI",450,200)
$progressbar    =  GUICtrlCreateProgress(10, 150, 430, 20)
GUISetState(@SW_SHOW)

$FILE = FileOpen($PATH, 0)
For $INDEX = 1 To _FileCountLines($PATH)
    $LINE = FileReadLine($FILE,$INDEX)
    $FIND = StringInStr($LINE,$search)
    If Not @error And $FIND <> 0 Then MsgBox(48,"Found!",$LINE)
    GUICtrlSetData($progressbar,$INDEX)
Next
FileClose($FILE)

MsgBox(64, "Search", "Finished!")

Exit

I know this is wrong so i didn't publish it at the first place...

Share this post


Link to post
Share on other sites
water

You have to specify percent so the script should look like:

#include <File.au3>

$message = "Open Log file..."

$PATH = FileOpenDialog($message, @WorkingDir & "", "Log (*.log)", 1 + 4)
If @error Then Exit

$search = InputBox("Search", "What to serch for", "")

$Form = GUICreate("GUI", 450, 200)
$progressbar = GUICtrlCreateProgress(10, 150, 430, 20)
GUISetState(@SW_SHOW)

$FILE = FileOpen($PATH, 0)
$iRecords = _FileCountLines($PATH)
For $INDEX = 1 To $iRecords
    $LINE = FileReadLine($FILE, $INDEX)
    $FIND = StringInStr($LINE, $search)
    If Not @error And $FIND <> 0 Then MsgBox(48, "Found!", $LINE)
    GUICtrlSetData($progressbar, Int($iRecords * 100 / $INDEX))
Next
FileClose($FILE)

MsgBox(64, "Search", "Finished!")

Exit

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

With all due respect, this not working :

Progress bar went from 0-100% less than a second..

This app need to work on xp intel celeron 2.4ghz

Edited by tempman

Share this post


Link to post
Share on other sites
water

I see. But this works - tested ;)

#include <File.au3>

$message = "Open Log file..."

$PATH = FileOpenDialog($message, @WorkingDir & "", "Log (*.log)", 1 + 4)
If @error Then Exit

$search = InputBox("Search", "What to serch for", "")

ProgressOn("Searching Log Files", "Log File: " & $PATH)
$FILE = FileOpen($PATH, 0)
$iRecords = _FileCountLines($PATH)
For $INDEX = 1 To $iRecords
    $LINE = FileReadLine($FILE, $INDEX)
    $FIND = StringInStr($LINE, $search)
    If Not @error And $FIND <> 0 Then MsgBox(48, "Found!", $LINE)
    $percent = Int(($INDEX * 100) / $iRecords)
    ProgressSet($percent, $percent & "%")
Next
ProgressOff()
FileClose($FILE)

MsgBox(64, "Search", "Finished!")

Exit

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

Yes, thank you for this, but Progress bar is always on top, so when message box appears it is behind Progress bar.

Can that be fixed?

Cheers!

Share this post


Link to post
Share on other sites
water

Sure:

#include <File.au3>

$message = "Open Log file..."

$PATH = FileOpenDialog($message, @WorkingDir & "", "Log (*.log)", 1 + 4)
If @error Then Exit

$search = InputBox("Search", "What to serch for", "")

ProgressOn("Searching Log Files", "Log File: " & $PATH, "", default, (@DesktopHeight/2)-250, 2)
$FILE = FileOpen($PATH, 0)
$iRecords = _FileCountLines($PATH)
For $INDEX = 1 To $iRecords
    $LINE = FileReadLine($FILE, $INDEX)
    $FIND = StringInStr($LINE, $search)
    If Not @error And $FIND <> 0 Then MsgBox(48, "Found!", $LINE)
    $percent = Int(($INDEX * 100) / $iRecords)
    ProgressSet($percent, $percent & "%")
Next
ProgressOff()
FileClose($FILE)

MsgBox(64, "Search", "Finished!")

Exit


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tempman

Cheers mate!!!

I find also this:

262144 MsgBox has top-most attribute set 0x40000

so if this:

If Not @error And $FIND <> 0 Then MsgBox(48, "Found!", $LINE)

change to this:

If Not @error And $FIND <> 0 Then MsgBox(262144, "Found!", $LINE)

problem is also solved!

Thank you for your time...

Edited by tempman

Share this post


Link to post
Share on other sites
water
:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×