Page 1 of 1

Linebreak not working

Posted: 07 Nov 2020, 13:03
by scriptor2016
Hi everyone!

I'm out of ideas... why is this line of code not working? It should be writing the data on seperate lines (because of the `n linebreak) but it's writing everything on one line.

What's wrong here? Thanks..

Code: Select all

fileappend,  `nDOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, C:\MyTextFile.txt

Re: Linebreak not working

Posted: 07 Nov 2020, 13:19
by mikeyww
It worked when I tested it. Is this the entire script? Can you paste (here) the output that you see? What are the values of title and Clipboard?

Do the following commands lead to the expected output?

Code: Select all

MsgBox,, Title, #%title%#
MsgBox,, Clipboard, #%Clipboard%#
Are you using a text editor that shows carriage returns and line feeds normally?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:24
by scriptor2016
thanks mikeyww

a sample of %title% would be:
mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *

and a sample of %clipboard% would be:
Texture - Grain


are these samples somehow throwing it off?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:26
by mikeyww
Possibly, because % is a special character, so it depends on how you handle it. Try the following.

Code: Select all

title := "mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *"
Clipboard = Texture - Grain
out = C:\MyTextFile.txt
FileRecycle, %out%
fileappend,  `nDOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, %out%
FileRead, ttext, %out%
MsgBox,, Results, %ttext%
If you have * accidentally before the file name (but you did not have that in your example), you will also disable end-of-line translation, which will omit carriage returns.

Are you somehow using a Unix file, editor or display for Unix files, or Unix encoding?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:35
by Smile_
@scriptor2016 , Your script is working just fine for me!

Re: Linebreak not working

Posted: 07 Nov 2020, 13:35
by scriptor2016
hmmm, I think the problem is indeed with the %title% portion. Here's a little more of what I was doing:

Code: Select all

wingettitle, title, A

out = C:\MyTextFile.txt
FileRecycle, %out%

fileappend, DOCUMENT NAME:`n%title%`nBRUSHES USED:`n%clipboard%, %out%

FileRead, ttext, %out%
MsgBox,, Results, %ttext%
and this still doesn't work. Looks like I need to somehow get %title% to be in the quotation marks, but how do I do that when it's a variable?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:38
by mikeyww
Can you show a screenshot of the message box?

What is the result of:

Code: Select all

MsgBox,, Clipboard, #%Clipboard%#

Re: Linebreak not working

Posted: 07 Nov 2020, 13:39
by scriptor2016
edit - thanks guys!! Looks like it's working now.

But here's the issue:

I was viewing the output file in Notepad. And it shows everything written on one line.

But if I view the output file in Notepad++, it shows it on several lines. Which is very confusing. i tried Notepad with Wordwrap both on and off and same results, everything on one line. Any idea why that might be?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:42
by mikeyww
Sounds like an issue with line feeds. If you paste the text at the following Web site, you can see the control codes.

https://www.soscisurvey.de/tools/view-chars.php

I don't think that Notepad has a way to alter the display of those characters, so perhaps this Web page will be informative.

Here is how my earlier script looks at the Web page.

Re: Linebreak not working

Posted: 07 Nov 2020, 13:50
by scriptor2016
does that mean that
mypicture-Recovered-Recovered.psd @ 30.5% (Color, RGB/8) *

contains invisible characters that Notepad cannot see, resulting in the `n linefeed to fail?

Re: Linebreak not working

Posted: 07 Nov 2020, 13:56
by mikeyww
That would be surprising-- but the idea is to figure it out-- so if you just copy the text in your output file and paste it onto that Web page, you will be able to see everything. If you see the normal CR LF sequences, then perhaps there is some other issue at hand.

Re: Linebreak not working

Posted: 07 Nov 2020, 14:01
by boiler
Notepad needs both CR and LF to actually show line breaks — at least older versions did. Files with only a LF, such as those that come from MacOS, will not be shown with breaks between the lines. Windows 10 updates have supposedly changed that. Perhaps you are using an older version of Windows.

Re: Linebreak not working

Posted: 07 Nov 2020, 14:04
by scriptor2016
Yes, I'm still on Windows7 64-bit. My motherboard is an older one and I don't think it supports Windows 10, so I'm in for a big headache when it comes time to update my system :(

Re: Linebreak not working

Posted: 07 Nov 2020, 14:05
by mikeyww
That's helpful to know; thanks.

With EOL translation, it's not clear why line feeds would be omitted from the output, but the idea is to see if that is the case.

Re: Linebreak not working

Posted: 07 Nov 2020, 14:05
by mikeyww
I'm also on Win7 Pro 64-bit and do not have trouble with the line feeds.

Perhaps look at the Web page?

Re: Linebreak not working

Posted: 07 Nov 2020, 14:10
by scriptor2016
yes sorry, I looked at the page. But it's a little beyond my level of knowledge lol

I pasted the %title% and then was a little lost as to what it was doing :(

Re: Linebreak not working

Posted: 07 Nov 2020, 14:18
by mikeyww
You have a text output file that you created. Open that file in Notepad++. Select all of the text. Press ^c to copy it to the clipboard. Go to the Web page. Paste it there, in place of the default text on that page. Click on "Show me the characters". See what is there. It will show the CR and LF symbols if they are present.

Re: Linebreak not working

Posted: 07 Nov 2020, 16:49
by TAC109
@scriptor2016
Check the EOL section of FileAppend. Although it is badly worded, in essence it is saying that all `n get translated to `r`n (normal Windows end of line) unless the data already contains one or more `r`n . I suspect that in your case, somewhere in the data being appended there is already one or more `r`n.

To fix, change your FileAppend to something like this:

Code: Select all

fileappend, % StrReplace("DOCUMENT NAME:`n" title "`nBRUSHES USED:`n" clipboard,"`r"), %out%
Cheers

Re: Linebreak not working

Posted: 07 Nov 2020, 17:05
by mikeyww
Hey, that's good to know! Thank you, @TAC109.

I ran a test.

Code: Select all

FileAppend, this`nthat`nthe other`r`n, %TEMP%\test.txt
Indeed, the problem was reproduced.

Re: Linebreak not working

Posted: 08 Nov 2020, 04:03
by scriptor2016
TAC109 , thanks!!

This actually works - Notepad now shows the text with the line breaks properly. Strange how that works. Haven't seen that problem before.

Thanks to everyone who took a look at this. It was totally baffling to me, I thought maybe it was a bug or something.