Sign in to follow this  
Followers 0
jorgeng

filewrite proper syntax

15 posts in this topic

Hello.

I have an autoit-script which reads a file every minute and does a compare with another file.

If the files differ we write the first file with filewrite.

It works but there are now strings with timestamp some times a day so the outputfile looks messy.

how do i do so every line written has an eof mark, meaning i want the new message on a new line

Now it looks:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$ 14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

I want:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$

14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

Part of my code:

FileWrite($file_Omx_Wampa, $var_original & @CRLF)

Share this post


Link to post
Share on other sites



Hello.

I have an autoit-script which reads a file every minute and does a compare with another file.

If the files differ we write the first file with filewrite.

It works but there are now strings with timestamp some times a day so the outputfile looks messy.

how do i do so every line written has an eof mark, meaning i want the new message on a new line

Now it looks:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$ 14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

I want:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$

14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

Part of my code:

FileWrite($file_Omx_Wampa, $var_original & @CRLF)

FileWriteLine(), or if you want a consistent Date/Time stamp added to each line try _FileWriteLog().

See help file.

:P


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

#3 ·  Posted (edited)

FileWriteLine(), or if you want a consistent Date/Time stamp added to each line try _FileWriteLog().

See help file.

:P

Sorry, filewriteline doesn't work, still same result, any other ideas?

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$ 14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 16:26 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

Edited by jorgeng

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_FileWriteToLine??

you could use _FileCountLines($sFilePath) + 1 as the line to write to too.

MDiesel

edit: Don't use the macro @CRLF on this one - as it could read this as a line

Edited by mdiesel

Share this post


Link to post
Share on other sites

Try adding the macro @CRLF to the end of the string.

Am i missing the point? I thought the idea was to make a log that could be edited by scripts run at different times. using @CRLF does NOT solve this problem - It is made for writing files, rather than editing them..

am I being stupid again?

MDiesel

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I seems as though we are not understanding what you are wanting to achieve. Could you try and describe your requirements in a different way to make it clearer.

In the mean time does any of this help?

$Data = "14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$ 14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$"
$Data = stringReplace($Data,'$ ', "$" & @CRLF)
fileWrite(Test.text,$Data)oÝ÷ Ù«­¢+ØÀÌØí¥±
½¹Ñ¹ÑÌô¥±I ÅÕ½Ðí¥±¹µÅÕ½Ðì¤(ÀÌØí½ÉµÑÑ¥±
½¹Ñ¹ÑÌôÍÑÉ¥¹IÁ± ÀÌØí¥±
½¹Ñ¹ÑÌ°ÌäìÀÌØìÌäì°ÅÕ½ÐìÀÌØìÅÕ½ÐìµÀì
I1¤)¥±]É¥Ñ ÅÕ½Ðí9Ý¥±¹µÅÕ½Ðì°ÀÌØí½ÉµÑÑ¥±
½¹Ñ¹ÑÌ
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks for help

Sorry if I am not clear for what i want. The text you see above i can log in to my webplace and look at - a simple htm file.

I only wants the formatting to be correct since when a new message comes as first position in file i want it on a a new line.

Today it's messy and all text appends at last where previous message stopped to write to file

Now it looks:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$ 14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$ 14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

I want:

14:27 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.2500$

14:28 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

14:40 ANALYS "sl) Omx Nexu Sellstop - Kl.11 - Rosa - Krypterat OMXS309C" kurs 662.7500$

I will try

_FileCountLines($sFilePath) + 1

as diesel suggested, come back if it works

Thanks

Edited by jorgeng

Share this post


Link to post
Share on other sites

Sorry, can't still get it to work, got error 2 from some file:

$CountLines = _FileCountLines($file_Omx_Wampa)

MsgBox(4096, "$CountLines", $CountLines)

$CountLines = $CountLines + 1

MsgBox(4096, "$file_Omx_Wampa", $file_Omx_Wampa)

MsgBox(4096, "$CountLines", $CountLines)

MsgBox(4096, "$var_original", $var_original)

_FileWriteToLine($file_Omx_Wampa, $CountLines, $var_original,0)

MsgBox(4096, "@Error", @Error)

FileClose($file_Omx_Wampa)

Share this post


Link to post
Share on other sites

If it's an .htm document, then put an html line break "<br>" in it:

FileWriteLine($sFileName, $sData & "<br>")

:P


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

If it's an .htm document, then put an html line break "<br>" in it:

FileWriteLine($sFileName, $sData & "<br>")

:P

Thanks, I try it.

Share this post


Link to post
Share on other sites

Yes, it worked, se log. At 17.19 the lines look correct. Great. Thanks.

:P

09:45 ORDER "sl) Omx Wampa - Stega till Sekvens 9A Kl.09.45 - Okrypterat OMXS309C" kurs 672.0000$ 10:00 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS309C" kurs 670.2500$10:00 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS309C" kurs 670.2500$ 12:54 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS309C" kurs 663.5000$ 17:18 ORDER "sl) Omx Wampa - Nollställ Depå kl.17.18 - Krypterat OMXS309C" kurs 660.5000$

17:19 ORDER "sl) Omx Wampa - Nollställ Depå kl.17.18 - Krypterat OMXS309C" kurs 660.0000$

17:19 ORDER "sl) Omx Wampa - Nollställ Depå kl.17.18 - Krypterat OMXS309C" kurs 659.5000$

17:20 ORDER "sl) Omx Wampa - Kurs Ovanför Kl.10 Stapel High - Eller Kl.17.20 OMXS309C" kurs 657.2500$

17:20 ORDER "sl) Omx Wampa - Kurs Ovanför Kl.11 Stapel High - Eller Kl.17.20 OMXS309C" kurs 657.2500$

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Sorry, can't still get it to work, got error 2 from some file:

$CountLines = _FileCountLines($file_Omx_Wampa)

MsgBox(4096, "$CountLines", $CountLines)

$CountLines = $CountLines + 1

MsgBox(4096, "$file_Omx_Wampa", $file_Omx_Wampa)

MsgBox(4096, "$CountLines", $CountLines)

MsgBox(4096, "$var_original", $var_original)

_FileWriteToLine($file_Omx_Wampa, $CountLines, $var_original,0)

MsgBox(4096, "@Error", @Error)

FileClose($file_Omx_Wampa)

You need to include file.au3

This method should work in htm files too, the error you were getting before looks like it was becouse it didn't recognise @CRLF or something...

If the other method works fine then don't bother. If it ain't broken, don't try to fix it (I have made this mistakes many times and ended up worse off than I started!)

Glad It's working

MDiesel

Edited by mdiesel

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

You need to include file.au3

This method should work in htm files too, the error you were getting before looks like it was becouse it didn't recognise @CRLF or something...

If the other method works fine then don't bother. If it ain't broken, don't try to fix it (I have made this mistakes many times and ended up worse off than I started!)

Glad It's working MDiesel

He's viewing the .htm document in a browser, so no amount of @CRLF is going to help until he gets an HTML line break ( "<br>" ) in there.

:P

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

He's viewing the .htm document in a browser, so no amount of @CRLF is going to help until he gets an HTML line break ( "<br>" ) in there.

:P

This method should work in htm files too, the error you were getting before looks like it was becouse it didn't recognise @CRLF or something...

basically what I was saying said properly with an explanantion given...

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