Jump to content

saving an array after _ArrayPush


Jury
 Share

Recommended Posts

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

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...