Jump to content

Recommended Posts

Posted
While 1
    $chars = FileReadLine($vrFchConf, 1)
    If @error Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($vrFchConf)

Read the documentation for FileReadLine ;)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>

#Region ### START Koda GUI section ### Form=c:\users\administrateur\documents\bot\interface\general.kxf

Global $currentVersion = 400
Global $GUI = GUICreate("DBG" & $currentVersion & "", 595, 539, 191, 126, -1, $WS_EX_TOPMOST)
Global $Tab1 = GUICtrlCreateTab(8, 8, 577, 513)
Global $TabSheet2 = GUICtrlCreateTabItem("Dofbot G4")
Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt",1)
Global $journal = GUICtrlCreateEdit("", 16, 48, 257, 329, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_VSCROLL))
GUISetState(@SW_SHOW)
Global $optionDebug = 0
#EndRegion ### END Koda GUI section ###

While 1
    $chars = FileReadLine($journalFile, 1)
    If @error Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($journalFile)

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

  • Developers
Posted

Please start reading the helpfile and try to understand  what it is you are coding as your script is reading forever record 1 of file so obviously will never encounter en EOF (thus @error)!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Hey YuChan,

You are trying to read first line over and over again. And getting the messagebox

Global $iLine = 1
While 1
    $chars = FileReadLine($journalFile)
    If @error Then ExitLoop
    ConsoleWrite("Line: " & $iLine & " > " & $chars & @CRLF) ; * See below
    $iLine += 1
Wend

; * : Replace consolewrite () with what you actually want to do with the read string, as it is you are not doing anything

@Jos beat me to it

Edit:

Open "Output" pane from View menu in SciTe to see console.

Would the part I added miss last line? Or error=-1 is set after reading the last line?

Edited by GokAy
Posted

@GokAy Good catch, but you forgot to modify the function call to FileReadLine to include $iLine :)

Global $iLine = 1
While 1
    $chars = FileReadLine($journalFile, $iLine)
    If @error Then ExitLoop
    ConsoleWrite("Line: " & $iLine & " > " & $chars & @CRLF) ; * See below
    $iLine += 1
Wend

; * : Replace consolewrite () with what you actually want to do with the read string, as it is you are not doing anything

 

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted

Sorry but i not understand.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>

#Region ### START Koda GUI section ### Form=c:\users\administrateur\documents\bot\interface\general.kxf

Global $currentVersion = 400
Global $GUI = GUICreate("DBG" & $currentVersion & "", 595, 539, 191, 126, -1, $WS_EX_TOPMOST)
Global $Tab1 = GUICtrlCreateTab(8, 8, 577, 513)
Global $TabSheet2 = GUICtrlCreateTabItem("Dofbot G4")
Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt",1)
Global $journal = GUICtrlCreateEdit("", 16, 48, 257, 329, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$WS_VSCROLL))
GUISetState(@SW_SHOW)
Global $optionDebug = 0
#EndRegion ### END Koda GUI section ###

While 1
    $chars = FileReadLine($journalFile, 1)
    If @error Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($journalFile)

While 1
    $nMsg = GUIGetMsg()

    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

It's my code.

What's i have fail in code for have one loop unlimited ?

  • Developers
Posted
1 hour ago, TheDcoder said:

but you forgot to modify the function call to FileReadLine to include $iLine

... and why would you want to do that in stead of the default "next line" as in that example? :) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Developers
Posted
3 hours ago, GokAy said:

Would the part I added miss last line? Or error=-1 is set after reading the last line?

Have you tried to get the answer? :) 

Spoiler

All lines will be shown. @Error is set after the last line is read.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

  • Developers
Posted
1 hour ago, YuChan said:

It's my code.

What's i have fail in code for have one loop unlimited ?

Apply what we told you in stead of simply posted the same code again! 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Hey all,

@TheDcoder No, I didn't forget to put in $iLine, it was merely for displaying line number for console output. Should have mentioned that though :)

@Jos I had to go out, so could only test it now. So @error is set afterwards, and it is ok.

However, I noticed another mistake in YuChan's code. FileOpen with mode 1 (append mode) does not read any lines in my test. Default 0 works (as mentioned in FileReadLine details).

Global $journalFile = FileOpen(@ScriptDir & "\dofbotJournal.txt") ; don't use mode 1

image.png.385fedf6772cb598469ea3407d51bf12.png

Edited by GokAy
Posted

@Jos @GokAy Oops, didn't realize FileReadLine kept track of the last read line by default (it was mentioned in the remarks, which I did not read). In any case, if you are already keeping track of the line no., it is better to explicitly pass it to FileReadLine as well :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

@TheDcoder If you need the line number for something, yes. I would remove it altogether after making sure everything is working as intended though. No need for avoidable computation.

Edited by GokAy
Posted

@GokAy, minor point but

06D7EEA0-AB2D-420E-9692-D37C9D0E75EB.jpeg.73e173e9346ef06a5c5b368b556f889f.jpeg

putting Global declarations within loops is probably not the best practice - besides having a (very) slight performance penalty, it causes considerable cognitive dissonance for those of us who come from other environments where such a construct is inconceivable :)  

Good catch on the FileOpen mode...

Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...