Jump to content
Macro Express Forums

Copying 'nothing' to the clipboard?


Recommended Posts

I'm sure we've covered this at least once before, but it apparently didn't stick and so far I've not found the relevant thread.

 

My macro includes commands that copy the text in a text window or box to the clipboard. But suppose I empty the text window in any of a variety of ways, e.g. by selecting all and hitting Delete or Backspace. After the clipboard copy command if I then display the clipboard's contents I see the previous non-empty value. How do I ensure that I get the expected null result please?

 

Edit: OK, found it thanks. Cory & Alan answered my similar question here.

 

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

However, I'm still having some problems in practice.

 

Suppose I open a new document in my text editor (or Notepad) and apply this macro:

 

Clipboard Empty

Clipboard Copy

Delay: 100 milliseconds

If Clipboard Equals ""

Text Box Display: // Empty.

Variable Set String %T[1]% to "" // Set T1 to empty.

Else

Text Box Display: // Not empty.

Variable Set String %T[1]% from the clipboard contents

End If

Text Box Display:

 

<CLIPBOARD EMPTY/>
<CLIPBOARD COPY/>
<DELAY Flags="\x02" Time="100"/>
<IF CLIPBOARD Option="\x00" CaseSensitive="FALSE"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Clipboard is empty.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _COMMENT="Empty."/>
<VARIABLE SET STRING Option="\x00" Destination="%T[1]%" _COMMENT="Set T1 to empty."/>
<ELSE/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Clipboard is not empty.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _COMMENT="Not empty."/>
<VARIABLE SET STRING Option="\x02" Destination="%T[1]%"/>
<END IF/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\font

 

That works as expected (the Empty message is displayed) if I do any of the following:

1. Nothing, just run the macro. (Text cursor is flashing beforehand and after.)

2. Use Ctl+A to select all, i.e. select all of nothing. (Text cursor is flashing beforehand and after.)

3. Type xyz, Ctl+A, Delete. (Text cursor is flashing beforehand and after.)

 

But as soon as I use Ctl+A a second time, so that the text cursor vanishes, running the macro always then displays the Not Empty message. I can never get back to the Empty state. This is despite the fact that the window appears empty (and there are no Return marks displayed if I use that feature in my text editor). And I get the message "T[1] = ".

 

It presumably comes down to the difference between 'empty' and 'null'. But it's a distinction I still don't grasp. In particular, what is the command If Clipboard Equals "" testing for, null or empty? I seem to recall that ME Pro has no proper 'Null' capability, so I assume it's testing for the state callled 'Empty'. IOW, the state where a value has at some stage been assigned but has been deleted. But if that's the case, why can I not recover that state?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Works for me.

..............................................

Again I'm wondering if you have something else going on in your system. I replicated your instructions 1-3 and inferred 4 was to enter a CTRL+A in the empty notepad as you described but it still reports that it's empty. Just as expected. I suggest that when you get one that appears empty take out the variable set string and tell MEP top instead save the clipboard value to a variable and then write that to a file. Then open that file in a hex editor to see what's happening.

 

Also your code was broken. Do you think in the future you could export a functional macro so we don't have to write one to replicate your code?

Link to comment
Share on other sites

I don't understand the second Ctrl+A either. It makes no difference in Notepad. Is your result due to the text editor you are using?

 

The Clipboard will not copy nothing. If you try that, the content of the Clipboard remains unchanged.

 

(edit) When ME copies "" to the Clipboard it registers as 00 at Offset 0 which is ASCII Null. It is not in an empty Clipboard state. Presumably on import, ME would see the Null but set the string to "". I would think that the first 32 ASCII characters with the exception of CR, LF and Tab would be ignored by ME as being invalid in an ANSI text string.

Edited by JohnS
Link to comment
Share on other sites

I don't understand the second Ctrl+A either. It makes no difference in Notepad. Is your result due to the text editor you are using?

 

The Clipboard will not copy nothing. If you try that, the content of the Clipboard remains unchanged.

 

(edit) When ME copies "" to the Clipboard it registers as 00 at Offset 0 which is ASCII Null. It is not in an empty Clipboard state. Presumably on import, ME would see the Null but set the string to "". I would think that the first 32 ASCII characters with the exception of CR, LF and Tab would be ignored by ME as being invalid in an ANSI text string.

 

Thanks. I'll do some more checks tomorrow, but I had same results in Notepad and TextPad.

 

BTW, my assumption that ME Pro could not test for a 'null' was based on this post by Kevin.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Never a null moment in this forum. The Null I'm referring to is the ASCII character NUL code 0, called Null! It's not Nil, Null, Empty or Blank; just the Null from the wrong side of the tracks!

Well, since the character is called NUL, why not use that name instead of the confusing Null?

 

To reiterate what has been stated before: in pure computer terminology (whatever that is when it's at home!), ME does not support NULL. A string variable contains a zero-length string before its first use; therefore a comparison of the string variable with "" will yield True. This is not a NULL, since a NULL is unknown and cannot be compared with anything else, not even another NULL, since that's also unknown. Even in real life, we would not claim that one unknown is equal to another unknown. And, of course, a zero-length string is not the same as a space (" "); a space is simply a character, just like "A" or "a".

And, finally, in MEP, a zero-length string appears not to be expressed at all:

Thus,

Variable Set String %t[1]% to "A"

is written as

<VARIABLE SET STRING Option="\x00" Destination="%t[1]%" Value="A"/>

while

Variable Set String %t[1]% to ""

is written as

<VARIABLE SET STRING Option="\x00" Destination="%t[1]%"/>

Note the absence of the Value= clause.

The same hold true for comparison tests.

Link to comment
Share on other sites

Thanks. I'll do some more checks tomorrow, but I had same results in Notepad and TextPad.

--

Terry, East Grinstead, UK

 

It seems I was mistaken about that. It turns out that the problem arises only in TextPad, not in Notepad.

 

Here's the test macro I used.

TestCopyToClipboard.mex

 

When I run it in Notepad it correctly reports 'Empty'. But in TextPad, despite showing T1 = "", it is not recognised as 'Empty'. This could explain a number of previous mysteries. I'll ask the author about it.

 

Anyone able to try it in another text editor please? Or indeed any text-handling window or dialog. I've tried a couple, but so far TextPad is the only one to display the problem.

 

My 'emptying' procedure was to select all and then either backspace or delete.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

I tried using Ctrl+A on a blank document in Metapad. The cursor stopped blinking per terrypin test. I copied to a blank ANSI text file and viewed in a Hex Editor, nothing. Copying and saving as a Unicode text file agreed with what I had found earlier. Unicode text files apparently start with FF FE even when empty. I copied a blank Unicode text file into T1 and displayed it in Text Box Display (y with diaeresis and small thorn) and then ran my macro that converts characters to ASCII value. Sure enough 255 and 254. So a blank Unicode file will not appear as blank to ME it would seem.

 

The concept of nulls in ME is IMO moot. It could be an interesting discussion(!) and of interest to someone programming in other apps. Most of us ignore nullness and take unset variables for what they are. Unset integers behave as 0, unset strings behave as "". I use that to my advantage. T99 is my designated null (I call it that) that I never set. If I want to clear a Text File I save T99 to it. If I want an infinite loop I "Repeat Until T99 = Never".

 

In a previous thread on arrays, one area that I highlighted was the fact that it is difficult to tell which members of an array have been set and which are either blank or 0. Arrays are a particular problem because they are often manipulated with Repeat loops or Split String commands. That makes tracking of a particular member difficult. The condition that is of real interest is "Set" or "Not Set".

 

The same applies to standard variables but they are easier to track. Generally speaking, every variable used is set. The only exception that comes immediately to mind is if you use "designated nulls" like I do.

 

Returning to arrays, I put in a request to ISS to have a flag to show a member has been Set. We can handle these things within ME by various means such as keeping track of array members that have been set. Far more difficult than having a 1 bit flag (though that may be difficult too if you have no spare bits). You can pre-seed an array with an identifiable value. Text arrays for example you could seed with "notset". Integer arrays are more tricky. In some recent work I set useless values to -1, something that would never happen with the true data.

 

To ensure we are using good data, external inputs have to be validated. That can be done in several ways:

1. Have forms that force the user to fill in every field - the form cannot be submitted otherwise

2. Pre-seed input values to say "notset" or "-1" or "1E40" so that invalid entries can be handled.

3. From other applications, handle on an individual basis depending on how they handle "nothing entered", or dare I say "null". The methods I've described for ME can be applied elsewhere. Some applications may have neat ways of telling you. If there is no workable method, then you simply cannot tell what is valid data.

Link to comment
Share on other sites

I got a bit sidetracked by the Unicode thing. If your second Ctr+A is supposed to be operated on of what is left after Step 3, I got no difference, Clipboard Empty, no value to T1. That was what I had found anyway by pasting to the ANSI text file.

 

What is this line supposed to do - surely to display the true value of T1 in the final Text Display Box this should be omitted?

Variable Set String %T[1]% to "" // Set T1 to empty.

If the Empty condition is found, this sets T1 to "", the same as "nothing" so the display is meaningless. Omitting the line made no difference.

 

I think the only reason the cursor stops blinking is that once you have selected text (even if nothing selected), the editor is not ready to accept typing.

 

The reason Cory complained was that the last Text Box Display was missing code. One assumes it was supposed to display T1.

Link to comment
Share on other sites

I got a bit sidetracked by the Unicode thing. If your second Ctr+A is supposed to be operated on of what is left after Step 3, I got no difference, Clipboard Empty, no value to T1. That was what I had found anyway by pasting to the ANSI text file.

 

What is this line supposed to do - surely to display the true value of T1 in the final Text Display Box this should be omitted?

Variable Set String %T[1]% to "" // Set T1 to empty.

If the Empty condition is found, this sets T1 to "", the same as "nothing" so the display is meaningless. Omitting the line made no difference.

 

I think the only reason the cursor stops blinking is that once you have selected text (even if nothing selected), the editor is not ready to accept typing.

 

The reason Cory complained was that the last Text Box Display was missing code. One assumes it was supposed to display T1.

 

My question was about my later macro TestCopyToClipboard.mex which hopefully should allow anyone to do a similar test in any window that accepts text. Delete the text any way you like,.

 

FWIW, here's its script too. Let me know if that doesn't answer your questions.

 

Clipboard Empty // This is to counter the odd fact that if there is nothing to copy, Windows/MEP still shows the clipboard contents as they were previously.

Text Type (Simulate Keystrokes): <CONTROL><HOME> // Select all text.

Delay: 100 milliseconds

Text Type (Simulate Keystrokes): <CONTROL><SHIFT><END> // Select all text. (Can't simply use <Ctl+A> because my intended target will be an IrfanView JPG Comments window, which oddly doesn't accept that standard shortcut.)

Delay: 100 milliseconds

Clipboard Copy

// My Preferences > Playback is set to 250 ms after 'clipboard commands'.

Variable Set String %T[1]% from the clipboard contents

If Clipboard Equals "" // Tests for clipboard containing "" (which I am calling 'empty').

Variable Set String %T[2]% to "Clipboard is empty."

Else

End If

Text Box Display:

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Paul:

 

Sorry if I'm making heavy weather of this but as a non-programmer I don't fully grasp much of what I've read about about 'nulls', 'zero-length strings', and the distinctions between ANSI, ASCII and Unicode etc. So, at a practical level, if you get a minute could you run my MEX file and see if you can find any other window that gives the same puzzling result.

 

To remind you, it worked as I'd expect in Notepad and the other windows I tried (including this message composition window, a convenient test target). IOW, after the text had first been manually deleted all gave the result:

 

Clipboard = T1 = ""

Clipboard is empty

 

But for Textpad, , the result was

 

Clipboard = T1 = ""

 

IOW, for some reason that I still haven't seen but which I suspect may be obvious to you , in the case of Textpad, the logic IF test If Clipboard Equals "" was not returning TRUE.

 

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

I didn't try the second macro because I thought it was the first as an mex file. I was feeling a little null at the time. If I added some confusion by talking about Unicode it was only because I was trying to duplicate the bizarre results you had.

 

I tried the mex. I assume that I was supposed to do your previous steps 1-3 plus 4 at the end (this time manually doing the typing actions because you did not use the text file). No differences.

Clipboard = T[1] =

Clipboard is empty.

every time with 3 different editors

 

The whole issue of nil, null, empty and blank I've never thought about. I observe how ME behaves and write code accordingly. I've never had occasion to scratch my head other than when importing from Excel and wondering how to tell which cells are deliberately blank and which have not been filled in. That has nothing to do with ME.

 

(edit) You should do what Cory suggested way back - look at the Clipboard in a Hex Editor to see what characters are being copied from TextPad. The only reason I can think that you have "Not Empty" but T1 = "" is that a character of hex value 0-31 (minus 9, 10, and 13) is put on the Clipboard and seen by ME. T1 is not equal to "" but the character is ignored and shown as "" because it is non-printable.

Edited by JohnS
Link to comment
Share on other sites

I didn't try the second macro because I thought it was the first as an mex file. I was feeling a little null at the time. If I added some confusion by talking about Unicode it was only because I was trying to duplicate the bizarre results you had.

 

I tried the mex. I assume that I was supposed to do your previous steps 1-3 plus 4 at the end (this time manually doing the typing actions because you did not use the text file). No differences.

Clipboard = T[1] =

Clipboard is empty.

every time with 3 different editors

 

The whole issue of nil, null, empty and blank I've never thought about. I observe how ME behaves and write code accordingly. I've never had occasion to scratch my head other than when importing from Excel and wondering how to tell which cells are deliberately blank and which have not been filled in. That has nothing to do with ME.

 

(edit) You should do what Cory suggested way back - look at the Clipboard in a Hex Editor to see what characters are being copied from TextPad. The only reason I can think that you have "Not Empty" but T1 = "" is that a character of hex value 0-31 (minus 9, 10, and 13) is put on the Clipboard and seen by ME. T1 is not equal to "" but the character is ignored and shown as "" because it is non-printable.

 

 

Thanks John. It really does seem to be unique to TextPad. The result of running that macro in many text windows is exactly as expected. The final message correctly reflects the state of the window at the time the macro was run.

 

The only exception I've found so far is TextPad. For a TextPad window that has been manually emptied (as distinct from one that has just been opened, with no text entered), the final message is different, just the one line:

 

Clipboard = T1 = ""

 

So the question is: why is TextPad in that situation wrongly reporting the clipboard as NOT being empty? As you implied, I think that for TextPad the Clipboard Copy command results in something being stored in the clipboard that is not stored by all the other applications. The result is that the logic IF test returns a result of FALSE, instead of TRUE.

 

I had tried the hex suggestion, fully expecting to find something 'special'. But opening either the TextPad or Notepad files in Hex Workshop (directly after the manual deletion and a file save) gives identical displays:

 

post-1217-1267976800_thumb.jpg

 

Edit: Got it! I realised that my hex test was probably flawed, so I've just done it again, this time exactly as Cory suggested. And now the results are different.

 

An empty Notepad window just displays 000000 as shown above. But Textpad displays this:

 

post-1217-1267979676_thumb.jpg

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

What you have there is a 10 and a 13 - looks like you've recorded a line feed which may have occurred with the Paste.

 

When you have been examining the value of T1, have you actually clicked to the right of the "=" to see if there are any spaces there? A space produces your effect. I simulated your effect using Hex but it turned out I had generated 2 spaces.

Link to comment
Share on other sites

What you have there is a 10 and a 13 - looks like you've recorded a line feed which may have occurred with the Paste.

 

Whatever is there was copied to the clipboard from an apparently empty TextPad by 'Clipboard Copy'. I'm hoping to hear back from the author.

 

When you have been examining the value of T1, have you actually clicked to the right of the "=" to see if there are any spaces there? A space produces your effect. I simulated your effect using Hex but it turned out I had generated 2 spaces.

 

What "=" are you referring to? And where in the script in Post #13 am I examining the value of T1?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Cory's only suggestion in this thread was to paste the clipboard into a text file and look at the hex values in that text file. Are you referring to another thread? I suggested in Post #15 that you look at the Clipboard content directly in your Hex editor.

 

I was using the second half of the mex file to evaluate Clipboard content:

Variable Set String %T[1]% from the clipboard contents
If Clipboard Equals "" // Tests for clipboard containing "" (which I am calling 'empty').
 Variable Set String %T[2]% to "Clipboard is empty."
Else
End If
Text Box Display:

The final TBD is

Clipboard = T[1] = %T[1]%
%T[2]%

My point is that when you reported results (in any of the posts!):

Clipboard = T1 = "" did you actually check the "" was really blank and not spaces

Link to comment
Share on other sites

Cory's only suggestion in this thread was to paste the clipboard into a text file and look at the hex values in that text file. Are you referring to another thread? I suggested in Post #15 that you look at the Clipboard content directly in your Hex editor.

 

You've lost me. It's helpful to use quotes for this sort of question, especialy in a long thread! Where am I possibly "referring to another thread"? Are you perhaps querying "I realised that my hex test was probably flawed, so I've just done it again, this time exactly as Cory suggested," in the edit to post #16?. If so, I described the flawed method I'd used beforehand, in the previous sentence of that same post: "...opening either the TextPad or Notepad files in Hex Workshop (directly after the manual deletion and a file save)...". (I assume it's because that manual save somehow altered the content.)

 

I was using the second half of the mex file to evaluate Clipboard content:

Variable Set String %T[1]% from the clipboard contents
If Clipboard Equals "" // Tests for clipboard containing "" (which I am calling 'empty').
 Variable Set String %T[2]% to "Clipboard is empty."
Else
End If
Text Box Display:

The final TBD is

Clipboard = T[1] = %T[1]%
%T[2]%

My point is that when you reported results (in any of the posts!):

Clipboard = T1 = "" did you actually check the "" was really blank and not spaces

 

Still not sure what you mean. How could there be any spaces in ""? The TextPad window itself obviously contained no spaces before the clipboard copy.

 

Anyway given that the problem has now been isolated to that TextPad oddity, why look any further? The only thing outstanding now is some explanation from TextPad's author, to satisfy my curiosity. And perhaps the discovery of any other text window that gives a similar problem.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Whenever you have reported results in this thread, when you made the test and examined what had been copied, did you click after the end of the string (which may have appeared as nothing) to check whether it contained spaces.

 

I know that spaces should not have been copied or created in doing the copy from TextPad (it's clearly creating something). If a space is created by that copy action, " " would appear to the casual viewer as nothing "" Your Clipboard test command would see the Clipboard as "Not Empty".

Link to comment
Share on other sites

It seems I was mistaken about that. It turns out that the problem arises only in TextPad, not in Notepad.
Many programs add terminating characters when you copy from them. Word often does that. I suggested that you save this varaible to a fiel then open it with a hex editor, did you try that?
Link to comment
Share on other sites

Unicode text files apparently start with FF FE even when empty. I copied a blank Unicode text file into T1 and displayed it in Text Box Display (y with diaeresis and small thorn) and then ran my macro that converts characters to ASCII value. Sure enough 255 and 254. So a blank Unicode file will not appear as blank to ME it would seem.
MEP does not support Unicode. And what's more it often causes problems as more and more apps are defaulting to Unicode. Essentially Unicode uses two bytes for every character and as you noticed has FF FE as it's format indicator. But MEP sees it as two non-sense characters.
Link to comment
Share on other sites

Clipboard = T1 = "" did you actually check the "" was really blank and not spaces
If there is a non-printing character with a byte value it could appear as nothing between two quote marks.
Link to comment
Share on other sites

Whenever you have reported results in this thread, when you made the test and examined what had been copied, did you click after the end of the string (which may have appeared as nothing) to check whether it contained spaces.

 

I know that spaces should not have been copied or created in doing the copy from TextPad (it's clearly creating something). If a space is created by that copy action, " " would appear to the casual viewer as nothing "" Your Clipboard test command would see the Clipboard as "Not Empty".

 

No spaces. I don't think I've been a 'casual viewer' during this long exercise! ;)

 

But now the good news: the problem has gone away!

 

This morning I ran that same macro again on an empty TextPad window (i.e. a new document window to which I'd added text and then deleted it). To my surprise the final message was now correct, i.e. it reported empty! I repeated the exercise many times, adding and deleting text in various ways beforehand, and got the same correct result every time.

 

My PC does a lot of house-keeping overnight so I rarely reboot it. But I did so last night after installing an automatic upgrade to PerfectDisk, my defragging program. So somehow the reboot resolved the problem. With hindsight I obviously wish I'd rebooted earlier, but everything was running smoothly in a whole range of major applications. And, this oddity apart, TextPad itself was performing in its usual solid fashion.

 

Keith MacDonald, TextPad's author said: "The characters with hexadecimal values 0D and 0A that you were getting on the clipboard are carriage return and linefeed, as I'd suspected, but the only way TextPad would do that is if the active document contains a single, empty line. Perhaps you had more than one instance of TextPad running, and your script picked up the wrong one."

 

I didn't have a second instance running so I'm still very curious to know what could have been happening! Not least because it could occur again, perhaps in a more obscure context (as I use TextPad intensively). But I suspect I'll now never know.

 

--

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...
×
×
  • Create New...