Sign in to follow this  
Followers 0
xcaliber13

Help with _FileWriteFromArray

8 posts in this topic

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

This:

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

should work!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

AutoBert,

             Thank you for the reply but still getting the same results.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

xcaliber13,

Just a thought.  If this data is being pulled from a DB then you can probably use SQL to get the formatting you want.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

BrewManNH,

                   Thank you!   That did the trick.   NH? = New Hampshire?       I am in Maine

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  
Followers 0