Jump to content

Recommended Posts

Hi All,

I want to make my progress bar progress with the amount of File lines read. 
How would I do this correctly. So far the code below can sometimes run in the middle of the progress bar and state completed.. and other times it can run into the 200%. 
 

;========================================================================
ProgressOn("TITLE", "ACTION")
;========================================================================
For $count = 1 To _FileCountLines($FileRead) Step 1
    $string = FileReadLine($FileRead, $count)
    $value1 = $input[1]
    $value2 = $input[2]
    $value3 = $input[3]
    $value4 = $input[4]

    $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF)
    ProgressSet($count, $count & "%")
    
Next
;========================================================================
;                               PROGRESS BAR OFF
;========================================================================
ProgressSet(_FileCountLines($FileRead), "Completed!")
Sleep(750)
ProgressOff()
;========================================================================

 

Share this post


Link to post
Share on other sites

.. more or less something like this:

;========================================================================
ProgressOn("TITLE", "ACTION")
;========================================================================
$iRows = _FileCountLines($FileRead)
For $count = 1 To $iRows Step 1
    $string = FileReadLine($FileRead, $count)
    $value1 = $input[1]
    $value2 = $input[2]
    $value3 = $input[3]
    $value4 = $input[4]

    $TM = FileWrite("C:\temp\test.txt", $value1 & " " & $value2 & " " & $value3 & " " & $value4 & @CRLF)
    
     $iPercent = Int($count / $iRows * 100)
    
    ProgressSet($iPercent, $count  & "/" & $iRows & @TAB & "(" & $iPercent & "%)")
    
Next
;========================================================================
;                               PROGRESS BAR OFF
;========================================================================
ProgressSet($iPercent, "Completed!")
Sleep(750)
ProgressOff()
;========================================================================

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

@Chimp, I took long to reply because I had to test the script. 
It works 100%. 

Thanks Chimp...

Share this post


Link to post
Share on other sites

With Binary..

;File read progress bytes
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
Local Const $KB = 1024
Local Const $CHUNKBYTES = 64 * $KB ;64 kb each read

Local $sFileName = SelectFile()
If Not FileExists($sFileName) Then Exit

Local $hFileRead = FileOpen($sFileName, $FO_BINARY) ;open in binary read mode

;file is already open get filesize this way instead of FileGetSize()
FileSetPos($hFileRead, 0, $FILE_END)
Local $iFileSizeBytes = FileGetPos($hFileRead)
Local $iFileSizeKB = Int($iFileSizeBytes / $KB)
Local $iRead, $sBinary, $iPercent
Local $FileData = ""

;========================================================================
ProgressOn("TITLE", "ACTION", "", Default, Default, $DLG_MOVEABLE)
;========================================================================

$iRead = 0
FileSetPos($hFileRead, $iRead, $FILE_BEGIN) ;Start reading from the pos $iRead in the file
ConsoleWrite("Reading " & $iFileSizeBytes - $iRead & " Bytes" & @CRLF)

;Note: Filesize limited by string size limit..
While $iRead < $iFileSizeBytes
    $iReadChunk = $CHUNKBYTES
    If $iReadChunk + $iRead > $iFileSizeBytes Then $iReadChunk = $iFileSizeBytes - $iRead
    $sBinary = FileRead($hFileRead, $iReadChunk)
    $iRead += @extended
    If @extended = 0 Or @error Then ExitLoop
    $FileData &= StringTrimLeft($sBinary, 2) ;remove 0x

    $iPercent = Int($iRead / $iFileSizeBytes * 100)

    If $iFileSizeKB > 10 Then
        ProgressSet($iPercent, Int($iRead / $KB) & "/" & $iFileSizeKB & "KB (" & $iPercent & "%)")
    Else
        ProgressSet($iPercent, $iRead & "/" & $iFileSizeBytes & "B (" & $iPercent & "%)")
    EndIf
WEnd
$FileData = "0x" & $FileData ;Need put 0x back
FileClose($hFileRead)

;Local $sConversionANSI = BinarytoString($FileData, $SB_ANSI)
;Local $sConversionUTF8= BinarytoString($FileData, $SB_UTF8)

ConsoleWrite("Writing data to " & @TempDir & "\test.txt" & @CRLF)
Local $hFileWrite = FileOpen(@TempDir & "\test.txt", BitOR($FO_OVERWRITE, $FO_BINARY))
FileWrite($hFileWrite, $FileData)
FileClose($hFileWrite)

;========================================================================
;                               PROGRESS BAR OFF
;========================================================================
Sleep(750)
ProgressSet($iPercent, "Completed!")
Sleep(750)
ProgressOff()
;========================================================================

Func SelectFile() ;From the helpfile
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."

    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST) ;"

    If @error <> 0 Then
        ;Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ;Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ;Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    EndIf
    ConsoleWrite($sFileOpenDialog & @CRLF)
    Return $sFileOpenDialog
EndFunc

 

Edited by Bilgus

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

  • Similar Content

    • By TheGreatMomo
      Here is the script for the variable I want to find:
      Local $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(138)
      The Item(138) for the span elemets is a dynamic number based on the index of all span objects on the webpage I am trying to send inputs to. 
      Based on the span.item(#) the corresponding InnerText for that element is the value that I want to get. Which I use the following script:
      Local $oSunHrs = $oSunHrsTD.InnerText
      Global $otime = _IECreate ("https://somewebsite.banana") _IELoadWait($otime) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oLinks = _IETagNameGetCollection($oFrameobj, "a") For $oLink In $oLinks If $oLink.ClassName = "linked formlink" Then _IEAction($oLink, "click") ExitLoop EndIf Next _IEloadWait($oFrameobj) Local $oMonHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(139) Local $oMonHrs = $oMonHrsTD.InnerText _IELoadWait($oFrameobj) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oMonHrs = _IETagNameGetCollection($oFrameobj, "SPAN") For $oMonHr In $oMonHrs If $oMonHr.ClassName = "aggregate_value" Then If $oMonHr.innertext >= "8" Then Local $oMonAdjHr = (8 - $oMonHR.Innertext) ConsoleWrite( $oMonHrs &@CRLF ) MsgBox (0, "Adjusted Value", $oMonAdjHr) ExitLoop EndIf EndIf Next  
      Where I get confused is how I find Item(#) if all I have is the InnerText. Since the InnerText is static and the Item# is dynamic:
      $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item( "x").InnerText = ("sometext")
      How can i get the X value??
       
    • By Vikramjeet
      $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 #include <MsgBoxConstants.au3> #Include <File.au3> Global $arlines WinActivate("MyApplication") ;Activate My Application Local $hWnd = WinWaitActive("MyApplication", "", 5) ;Wait for My Application for 5 seconds $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Open Excel file 'Data.xlsx' local $iCell = $oExcel.Application.Cells(31,1).Value ;Read the value from cell A31 $file = @ScriptDir & "\Capture.log" If $hWnd Then For $a = 1 to $iCell ;STEP 1 Send("G*L") Send($oExcel.Application.Cells($a,1).Value) Send("/XUSR") Sleep(1000) Send("{ENTER}") Sleep(2000) ;===> Once the script has sent the above formats to 'MyApplication, A log file (Capture.log) is generated. What do I add as a link so the script moves to ;the following steps _FileReadToArray ($file, $arlines) For $i = $arlines [0] To 1 Step - 1 ; Script starts reading the log file from bottom up If $arlines [$i] = "‡NOT VALID" Then ;===> If I find the word '‡NOT VALID', then I want the script to go to STEP 1 in loop Else ;====> Else I want the script to do the following steps Send("MB") ; Continue sending formats to 'MyApplication' Send("{ENTER}") Sleep(2000) $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ; Read number at a certain location in Capture.log file ConsoleWrite($iNum & @CRLF) EndIf ;====> Use the captured $iNum in the loop below. What do I add to proceed to the following steps For $i = 1 To $iNum Send("SET"& $i &"/USR") Sleep(500) Send("{ENTER}") Sleep(1000) ;====> Go back to STEP 1 $oExcel.Application.Quit I am a beginner and need help with If, then, else jump to specific loop in the script. Can I please get help with my script where I have multiple loops. I need to link the steps and also break the sequence and jump to specific loop if a certain condition is found in one loop. 
    • By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • By milkmoron
      Hi is there a move next function or a way to loop so that the next item in a record is selected? I'm not sure where to start looking in order to find them. I want to click a text link and then do my macros, which I'm already finished with and then make it move to the next record. This is on a web browser it looks like this. The link is a date. I believe the page uses javascript Theres also a button for the bottom and I want it to do a whole date range 1/1/2016 - 7/1/2018

    • By nacerbaaziz
      Hi dear
      I have a request
      I want a simplified example of how to create the toolbar
      With an example of pressing the buttons inside this bar
      for example
      Toolbar contains Three buttons
      open, save, And delete
      and i want  If i press a button from among these buttons a MSGBox appears
      I know this is easy
      But I did not know how to do it
      I hope you help me
      I apologize for the inconvenience
      Thank you in advance
×
×
  • Create New...