Need help testing format of data in the clipboard.

Loki

New member
Joined
Nov 24, 2005
Messages
2
Programming Experience
1-3
I'm trying to test the format of the data in the clip board using this code, the error message follows:

If Clipboard.GetDataObject.GetData(DataFormats.Text) Then
Me.Editor.Paste()
Else
MsgBox("no text to paste")
End If

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "<title> </title>
<meta http-e" to type 'Boolean' is not valid.


Please help!!!
 
Clipboard.GetDataObject returns an IDataObject object. The GetData method of an IDataObject actually gets the data in the specified format, so that expression returns a String, not a Boolean. To test whether the clipboard data is in the format you want you need to call GetDataPresent on the IDataObject. Checkout the help/MSDN topic for the Clipboard.GetDataObject method for a code example. The help/MSDN should always be the first place you look for help. If you can't find what you want or can't understand what you do find, then look elsewhere.
 
Note that if you are using VB 2005 you can also do this:
VB.NET:
If My.Computer.Clipboard.ContainsText() Then
and you could use the GetText method to get the text from the clipboard if you wanted.

You should note also that the help topic for the TextBox.Paste method also has a code example of exactly what you are trying to do. The help/ MSDN is your friend.
 
Back
Top