Jury Posted October 1, 2012 Share Posted October 1, 2012 I have searched but can't find anything about how to save an array after doing an _ArrayPush. I'm trying to save the array as a list with one array element to a line. This is what I've tried and it displays my array with Hello world! at the top but doesn't save it to the file. Thanking you, Joe #include <Array.au3> #include<File.au3> Dim $echrDone $echrdonefile = @MyDocumentsDir & '\AutoIt_code\getter\resources\ECHR_done.txt' $file = FileOpen($echrdonefile, 1) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open " & $echrdonefile) Exit EndIf FileClose($file) If Not _FileReadToArray($echrdonefile, $echrDone) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf $echrDone = _ArrayUnique($echrDone) _ArrayDisplay($echrDone, "$aRecords") _ArrayPush($echrDone, "Hello world!", 1) FileClose($file) _ArrayDisplay($echrDone2, "$avArrayTarget AFTER _ArrayPush() string to beginning") _FileWriteFromArray($file, $echrDone2, 1) Link to comment Share on other sites More sharing options...
water Posted October 1, 2012 Share Posted October 1, 2012 This adds the array to the end of the existing file: #include #include Dim $echrDone $echrdonefile = "C:temptest.txt" $file = FileOpen($echrdonefile, 1) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open " & $echrdonefile) Exit EndIf If Not _FileReadToArray($echrdonefile, $echrDone) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf $echrDone = _ArrayUnique($echrDone) _ArrayDisplay($echrDone, "$aRecords") _ArrayPush($echrDone, "Hello world!", 1) _ArrayDisplay($echrDone, "$avArrayTarget AFTER _ArrayPush() string to beginning") _FileWriteFromArray($file, $echrDone, 1) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
hannes08 Posted October 1, 2012 Share Posted October 1, 2012 Hi Joe, first you can leave out the part with the FileOpen() and FileClose()s :-) Too much code you don't need. Add an error check to your _FilereadToArray() and FileWriteFromArray() functions. (Get the returncode and @error macro) Look at the helpfile about _FileWriteFromArray(). Use the @CRLF macro as delimiter. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Jury Posted October 2, 2012 Author Share Posted October 2, 2012 Thanks for attempting to help me but the resulting file after _FileWriteFromArray is just the same file as the original file _FileReadToArray - I want to know how to end up with a saved a file that has the added Hello world! as the first line. Joe Link to comment Share on other sites More sharing options...
water Posted October 2, 2012 Share Posted October 2, 2012 To get the "Hello world" record in the output file you have to write the whole array and start with index = 0. Hence change _FileWriteFromArray($file, $echrDone, 1)to_FileWriteFromArray($file, $echrDone, 0) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Jury Posted October 2, 2012 Author Share Posted October 2, 2012 Water, That's the trick! Thanks for that I think I see the logic of this now. Chrres, Joe Link to comment Share on other sites More sharing options...
water Posted October 2, 2012 Share Posted October 2, 2012 My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now