Jump to content

FileReadToArray not updating in a loop


Recommended Posts

I am using _FileReadToArray() to read a TXT file in a loop and then send the array results to a GUICtrlCreateEdit(). It is in a loop because the TXT file will continue to be updated and I need the GUICtrlCreateEdit() to display these results.

Could someone please explain why the array is not updating after the TXT has been updated. Also is there possibly a better way to achieve this?

;EXAMPLE ONLY========================================

Opt("GUIOnEventMode", 1)

#include <GUIConstantsEx.au3>
#include <File.au3>

GUICreate("", 500, 500)
  Dim $edit = GUICtrlCreateEdit("", 10, 10, 480, 480)
  Dim $array
  GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUISetState()

While 1
  _FileReadToArray(@ScriptDir & "\file.txt", $array)
  If Not @error Then
    GUICtrlSetData($edit, "") ;clear edit field to avoid duplicates
    For $x = 1 To $array[0]
      GUICtrlSetData($edit, $array[$x] & @CRLF, 1)
    Next
  EndIf
  $array = "" ;clear array
  Sleep(5000) ;sleep for 5 seconds
WEnd

Func _exit()
  Exit
EndFunc
Link to comment
Share on other sites

Maybe the file file.txt is locked by another process when it is been updated?

How long is your file.txt?

Try this:

;EXAMPLE ONLY========================================

Opt("GUIOnEventMode", 1)

#include <GUIConstantsEx.au3>
#include <File.au3>

GUICreate("", 500, 500)
 $edit = GUICtrlCreateEdit("", 10, 10, 480, 480)
 GUICtrlSetLimit(-1, 0x7FFFFFFF)
 Dim $array
 GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
GUISetState()

While 1
 _FileReadToArray(@ScriptDir & "\file.txt", $array)
 If Not @error Then
    ConsoleWrite($array[0] & @CRLF & @CRLF)
    GUICtrlSetData($edit, "") ;clear edit field to avoid duplicates
    For $x = 1 To $array[0]
    GUICtrlSetData($edit, $array[$x] & @CRLF, 1)
    Next
 EndIf
 $array = 0 ;clear array
 Sleep(5000) ;sleep for 5 seconds
WEnd

Func _exit()
 Exit
EndFunc

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

To set specific colours in an edit, you can use a richedit rather then a normal edit and then use _GUICtrlRichEdit_SetCharColor, see the example in the helpfile.

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
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...