Jump to content
Sign in to follow this  
DarkBoost

FileReadToArray not updating in a loop

Recommended Posts

DarkBoost

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

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
DarkBoost

i found that the issue was i was not closing the file correctly in another function *doh*.

slightly off topic, can you set a specific color to a word in an edit box?

Share this post


Link to post
Share on other sites
Yoriz

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.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.