VB .NET copying to clipboard

447 views
Skip to first unread message

Ef

unread,
Feb 19, 2007, 11:32:48 PM2/19/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I have an application that currently copies to the clipboard using
Clipboard.SetDataObject(). The problem is that when I paste what was
copied carriage returns are returned as those ugly box symbols rather
than actual carriage returns. Anyone know a solution to this problem.
Thanks.

Cerebrus

unread,
Feb 20, 2007, 7:19:31 AM2/20/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I haven't faced this problem. What is the target application in which
you paste the text ? Can you post your code for review here ?

Ef

unread,
Feb 20, 2007, 11:33:47 AM2/20/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thanks for the replies. The code is below. The target application is
SQL Server Reporting Services, but I've noticed the same issue when I
paste to UltraEdit and Notepad. When I paste to Word I do not have the
same issue. I could easily highlight and copy everything within the
textbox but that defeats the purpose of the copy to clipboard
functionality. Thanks agian.

Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnCopyToClipboard.Click
Dim strParsedOutput = textParsedOutput.Text
Clipboard.SetDataObject(strParsedOutput)
End Sub

Joe Enos

unread,
Feb 21, 2007, 6:32:30 PM2/21/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
How is the text getting into the textbox in the first place? Is it
user input, or is it populated based on another function? If it's
coming from another function, how is that other function creating the
text? For example, is it using vbCrLf or Environment.NewLine or some
other method to create its line feeds, or are they coming from another
text file or XML file or database?

Ef

unread,
Feb 23, 2007, 11:12:50 PM2/23/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
The input is coming from the user. Actually it is copied from SQL
Server Mgmt. Studio as an MDX query. It is pasted in and then turned
into a regular expression (at least that is the attempt)

Cerebrus

unread,
Feb 24, 2007, 1:01:05 AM2/24/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I think Joe rightly deduced that the problem is at the source of your
text. What do you see when you paste the text from the MDX query into
an editor like UltraEdit/Notepad ? Are the boxes there ?

Ef

unread,
Feb 26, 2007, 12:08:42 PM2/26/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
When I paste the MDX query into notepad or UltraEdit those carriage
return symbols are not present.

Joe Enos

unread,
Mar 3, 2007, 11:43:03 AM3/3/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Something to try:
Validate the characters in your textbox one at a time to see exactly
what characters they are. I believe you should find both a carriage
return and a line feed in every break. If you find just a carriage
return or just a line feed, then replace it with both.

You could do something like this to test it - this will at least tell
you every character that appears in your textbox:

dim i as integer
dim s as string = txtbox.Text
for i = 1 to s.Length
if (s(i).ToString() = vbCr)
MessageBox.Show("vbCr")
elseif (s(i).ToString() = vbLf)
MessageBox.Show("vbLf")
elseif (s(i).ToString() = Environment.NewLine
MessageBox.Show("Environment.NewLine")
else
MessageBox.Show(s(i).ToString())
endif
end for

Charles A. Lopez

unread,
Mar 3, 2007, 12:06:17 PM3/3/07
to DotNetDe...@googlegroups.com
As Joe has mentioned you do need to Validate the characters. I would also recommend applying another method to the object. The carriage return and line feeds are messing you up.
 
In the code snippet the follows:
 
1. Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object,
2. ByVal e As System.EventArgs) Handles btnCopyToClipboard.Click
3.       Dim strParsedOutput = textParsedOutput.Text
4.       Clipboard.SetDataObject(strParsedOutput)
5. End Sub
 
I would call another method between line 3 and 4 to clean up the object strParsedOutput. Perhaps the method/function/procedure/subfunction could be the code joe@jtenos recommended.
 
 
Regards,
 
Charles A. Lopez
BA Computer Science - NYU
Aspiring EIT

Ef

unread,
Mar 9, 2007, 11:23:36 PM3/9/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Sweet. Thanks.

Reply all
Reply to author
Forward
0 new messages