Jump to content
Sign in to follow this  
IndyUK

File reading

Recommended Posts

IndyUK

Hi,

Using the file reading functions how can I prevent Autoit from ignoring line feeds as field delimiters? My function works ok if the line is one continous string, but if I have a linefeed in my Notes field it gets split. This obviously results in an array overflow error.

Thanks

Share this post


Link to post
Share on other sites
martin

Hi,

Using the file reading functions how can I prevent Autoit from ignoring line feeds as field delimiters? My function works ok if the line is one continous string, but if I have a linefeed in my Notes field it gets split. This obviously results in an array overflow error.

Thanks

Can you show some code because very little is obvious to me.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
IndyUK

Here's the file reading code...

$file = FileOpen($ComFile, 0)
; Check if file opened for reading OK
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
; Read in lines of text until the EOF is reached
    $aRecords = StringSplit(FileReadLine($file), ",")

    FileClose($file)

I'm reading the line into $aRecords array and splitting each field when the read encounters a ",". However, I have a notes field at the very end which a user submits text into. This text could be a single line or it could be a few sentences spaced out using CR/LF. The problem I'm having is the function only reads part of the notes field, i.e. up to where the carriage return is detected. What I want to do is to retain the carriage returns so the text remains as the user submitted it.

Thanks

Share this post


Link to post
Share on other sites
argumentum

I'm reading the line into $aRecords array and splitting each field when the read encounters a ",". However, I have a notes field at the very end which a user submits text into. This text could be a single line or it could be a few sentences spaced out using CR/LF. The problem I'm having is the function only reads part of the notes field, i.e. up to where the carriage return is detected. What I want to do is to retain the carriage returns so the text remains as the user submitted it.

Thanks

also paste a sample of the file, 2 or 3 records, to have an idea of what you are trying to interpret with the script

Share this post


Link to post
Share on other sites
IndyUK

Here's a sample file...

AI, Incident, Hardware, , Firstname, Surname, Name, Own PC, IT003786, email.address, This is

a test

Notice the last field which has a CR/LF. At the moment my last array element only gets the "This is" part and terminates.

Share this post


Link to post
Share on other sites
saywell

Here's a sample file...

AI, Incident, Hardware, , Firstname, Surname, Name, Own PC, IT003786, email.address, This is

a test

Notice the last field which has a CR/LF. At the moment my last array element only gets the "This is" part and terminates.

How about a lateral approach?

Read the whole file, replace the CRLFs with ANother character. then split with comma-delimitation.

Select the bit after the last comma then replace the other characters with CRLFs?

Not sure my programming is up to it, though!

William

Share this post


Link to post
Share on other sites
PsaltyDS

Here's a sample file...

AI, Incident, Hardware, , Firstname, Surname, Name, Own PC, IT003786, email.address, This is

a test

Notice the last field which has a CR/LF. At the moment my last array element only gets the "This is" part and terminates.

That is simply invalid CSV formatting.

If you can fix it on the source end, have it save proper CSV format with "<br>" or some other token for line breaks in the comment. This should be the preferred solution.

If you must deal with the screwed up source, then on splitting the string check the count in [0] = 1, which indicates this is another line as part of the previous line's comment field.

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×