Jump to content

Help with _FileWriteFromArray


Recommended Posts

Hi all,

      Quick question.   I run a script to pull data from a file. No problem there.   I do an _ArrayDisplay and the data is exactly in the format I want

Example of ArrayDisplay:

Name  Home address   DOB  age  work address 

But when I do _FileWriteFromArray the file is in this format:

Name

Home address

DOB

age

work address

I have tried different options with _FileWriteFromArray but the file is still in the wrong format.

Tried

_FileWriteFromArray("C:\TempMerge\temp.txt", $aFinalResults, 0, Default, @CRLF)

and

_FileWriteFromArray("C:\TempMerge\temp.txt", $aFinalResults, 0, Default, Default)

Both I have tried with the 0 set to a 1 but the temp.txt file still comes out in the wrong format.   What am I doing wrong?

Link to comment
Share on other sites

Post your script and a sample of the text file you're reading.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Here is the script:

#include <file.au3>
#include <Array.au3>
#include <String.au3>
#include <StringConstants.au3>
#include <Date.au3>
#include <Excel.au3>
#include <ExcelConstants.au3>
#include <MsgBoxConstants.au3>

$Date = StringFormat("%02u%02u", @MON, @MDAY) & StringRight(@Year, 2)
Local $sNewDate = StringRegExpReplace(_DateAdd("d", 0, _NowCalcDate()), '\d\d(\d\d).(\d\d).(\d\d)', '$2/$3/$1')

Local $aArray = 0
Local $sArray = 0

$sFilePath = ("C:\TempMerge\AALADemoMerged.txt")
$sFileCreate = ("C:\TempMerge\AALA.txt")
$sFile = FileRead($sFilePath)

;-----Pull Data from file----  Data is two sets of addresses Name1  and Name2
$aResults = StringRegExp($sFile, "(?i)(Patient Name.*\R.*\R.*\R.*)\R|(?i)(Guarantor Name.*\R.*\R.*\R.*)\R", 3)

; Some blank lines get pulled --  This deletes blank lines
while 1
    $newvar = _ArraySearch($aResults, "", 0, 0, 0, false); Search for null lines
    if @error = 6 Then; no more matches found
        ExitLoop
    Else
        _ArrayDelete($aResults, $newvar);Delete current full line
    EndIf
wend

; This takes the two sets of addresses and puts them on one line So each line starts with Name1
Local $aFinalResults[UBound($aResults)]

For $i = 0 to UBound($aResults) -1
   $aFinalResults[$i] = $aResults[$i] & " " & $aResults[$i+1]
   $i = $i+1
Next

For $i = UBound($aFinalResults) -1 To 0 Step -1
   If $aFinalResults[$i] = "" Then
       _ArrayDelete($aFinalResults, $i)
   EndIf
Next


_ArrayDisplay($aFinalResults)

_FileWriteFromArray("C:\TempMerge\temp.txt", $aFinalResults, 0, Default, @CRLF)

 

test.txt

Link to comment
Share on other sites

Change this line:

; From this
   $aFinalResults[$i] = $aResults[$i] & " " & $aResults[$i+1]
; To this
   $aFinalResults[$i] =StringReplace($aResults[$i] & " " & $aResults[$i+1], @CRLF, "")

Your script is adding a CRLF to every entry in the array after the text, this removes them.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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