Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

FileWriteFromArray doesn't represent changes that are applied to the array

$
0
0
I know this looks similar to some other posts. I looked at a few and 1 of them I thought for sure was the answer but it didn't work so in desperation I am starting this thread.

So, I have a large text file that I am looking to replace the words "RUN DATE" when certain criteria isn't met. I through some MsgBox feedback etc in here so I could better understand what is happening. It seems the logic is working. It finds the instances where the criteria is met and makes (appears to) changes to the array which is evident when it performs the "MsgBox(0, "String Replace State", $StringReplace)" function i.e. I see the change to that array in the result. The problem is that when I do a _FileWriteFromArray and then look at the new file that is created it doesn't reflect the changes made. I know I am very close but just can't seem to figure this one out. I did try changing the $i_Base to 0 specifically as was mentioned on another thread (Thought for sure that would work) but still the same problem.

Here is my ugly code...please don't laugh

[ autoit ]         
#include <Array.au3> #include <File.au3> $FileOpen = FileOpen ( "c:\trantest.txt") Local $TranText = FileRead("c:\trantest.txt") Local $TranArray = StringSplit($TranText, ' ', 1);This splits the .txt file into an array. Each array is the beginning of a new page which is what the 'FF' represents. MsgBox(0, "Number of Strings in Array", $TranArray[0]) For $i = $TranArray[0] To 1 Step -1;This checks how many arrays the page has been split into so that we can loop through each array to test for the condition we are looking for. $UnsignedTrans = 99999 ;We need to set an initial value here. If there is a page with RUN DATE that doesn't have the text 'Unsigned transcriptions" this value will be set to zero $Search = StringInStr ( $TranArray[$i], "RUN DATE") MsgBox(0, "Array Test", $Search) If $Search <> 0 Then   MsgBox(0, "String Found", "String Found in Array" & $i)   Global $UnsignedTransTest = StringInStr($TranArray[$i], "Unsigned transcriptions")     MsgBox(0, "Unsigned text exists?", $UnsignedTransTest)     $UnsignedTrans = $UnsignedTransTest     MsgBox(0, "2", $UnsignedTrans)      EndIf If $UnsignedTrans = 0 Then MsgBox(0, "Error at line", $i) Local $StringReplace = StringReplace($TranArray[$i], "RUN DATE", "xxxxxxx", 1) _ArrayDisplay($TranArray) $UnsignedTrans = 99999; this resets the variable so the next loop itteration can run correctly ;FileClose($FileOpen) $FileWrite = _FileWriteFromArray("C:\test.txt", $TranArray) MsgBox(0, "File Write State", $FileWrite) MsgBox(0, "File Write Error", @error) MsgBox(0, "String Replace State", $StringReplace)   EndIf Next MsgBox(0, "", "Blast Off!")

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>