Jump to content
Macro Express Forums

CR/LF Inside a Variable


Recommended Posts

So, to make life easier, I have a code snippet that looks like this:

<VARIABLE SET TO ASCII CHAR Value="13" Destination="%CRLF%"/>
<VARIABLE SET TO ASCII CHAR Value="10" Destination="%T[1]%"/>
<VARIABLE MODIFY STRING Option="\x07" Destination="%CRLF%" Variable="%T[1]%"/>

 

Then I can just drop the %CRLF% variable into a text-type or combine it with another variable and voilà, insta-carriage-return.

 

Except that it doesn't always work right. Take the following macro code for example:

<WINDOW ACTIVATE Title="Document1" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
<VARIABLE SET TO ASCII CHAR Value="13" Destination="%CRLF%"/>
<VARIABLE SET TO ASCII CHAR Value="10" Destination="%T[1]%"/>
<VARIABLE MODIFY STRING Option="\x07" Destination="%CRLF%" Variable="%T[1]%"/>
<REPEAT START Start="1" Step="1" Count="10" Save="TRUE" Variable="%N[1]%"/>
<TEXT TYPE Action="1" Text="Test%N[1]%%CRLF%"/>
<END REPEAT/>

 

If I leave it as "Use clipboard to paste" the macro ignores the %CRLF% altogether. If I change it to "Simulate keystrokes,"

I get a fresh new line with each "Test."

 

I imagine it has something to do with the clipboard not knowing how to paste a carriage return... except that it should, since

I can copy lines of text that have carriage returns in them and the clipboard pastes them just fine.

 

What am I misunderstanding about this process? Or am I missing nothing and should file a bug rep?

Link to comment
Share on other sites

It's something with your editor. If I execute in UltraEdit or Notepad it works. If I do it in Word it fails. Interestingly they are coming out as spaces there. It's something Word is doing like Excel molests stuff to be clever.

 

FWIW I used to have a single CRLF but now I use CR and LF as separate. This is handy because there are a few times I want to find the end of a line easily. If I look for the position of %CRLF% it's one character from the end and I have to increment. If they are separate I can search for %LF% and avoid the increment. There are a few different scenarios like, EG soft CRs or reports which are not DOSish, that and I find it worth the added flexibility.

Link to comment
Share on other sites

Confirmed. I put "Test<CRLF>" in UltraEdit and confirmed the line ended with 0D0A. Copied it to the clipboard and pasted into Word. Word converts it to a space. Then pasted back in UE to confirm clip still has CRLF. I know what's happening. Word is being clever. I'm guessing that the programmers at MS were thinking "Hmmmm... Often people accidentally catch a CR LF on the end of a bit of text and if they paste it in they will cause a new paragraph so we'll just take care of that for them." I also notice d if you paste a block of text with several carriage returns it only removes the last one. You know Word is a format based editor and given that one should never use CR for line spacing so I can see where there logic is going.

Link to comment
Share on other sites

It's something with your editor. If I execute in UltraEdit or Notepad it works. If I do it in Word it fails. Interestingly they are coming out as spaces there. It's something Word is doing like Excel molests stuff to be clever.

Hmm, that's odd. I usually use Notepad, but I had Word open and chose to use it as a testing ground. After reading your post, I opened Notepad, re-did the Activate command and tried again. Strangely, my first run gave me this:

Test1Test1Test1

Test3

Test4

Test5

Test6

Test7

Test8

Test9

Test10

Further runs gave me the desired results.

 

So weird.

Link to comment
Share on other sites

My tests gave similar results to Cory's. The paste method worked fine into both Notepad and my text editor, TextPad. But Word wouldn't enter the CRLFs, and nor would Excel.

 

Turning to less obvious targets, IrfanView (my main image viewer), handled both options OK, typing into its text box. But my main image editor, PaintShop Pro wasn't having any of it and went off doing random stuff, with both text typing options. Windows' built-in image editor, Paint, (which needed a Mouse Move and Left Click adding to identify the target) worked OK with Simulate but not Clipboard Paste. In the latter case it gave erratic results, sometimes entering just one value (e.g. 'Test3') and in other runs typing nothing. Yet, with the macro ended, if I then used <Ctl+v> the correct value 'Test10' was always pasted in. Similar to your own experience.

 

I tried various timing changes, such as in Options > Preferences > Playback and adding a Keystroke Speed (with crazy values right up to 200 ms). But with no success for those applications.

 

I'm inclined to regard this as a bug. The specification doesn't seem to define any restrictions. Maybe there's some work-around, perhaps varying by application, but for practical purposes life's too short to explore that!

 

However, I never use the Clipboard Paste method myself. It's clearly undesirable in this case, but does it have some advantages I'm missing?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...