By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

Working with clipboard

P: n/a
I am working on an application that needs to parse out data that has been
copied into the clipboard. My first questions are how can I detect if the
clipboard is empty, and how can I empty the clipboard? I tried the code
below, but it didn't seem to tell me if the clipboard was empty.
If Clipboard.GetDataObject() Is Nothing Then
MessageBox.Show("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDataObject()
If (txtdata.GetDataPresent(DataFormats.Text)) Then
MessageBox.Show(txtdata.GetData(DataFormats.Text))
End If
End If

Also, the data that is being copied is basically a 8000 line document
containing data plots from an instrument in our labs. I need to grab
certain data from the third line. Any suggestions on how to do this?

Thanks.
Joshua
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Joshua Campbell" <Jo*************@WellmanInc-DieSpamDie.com>
schrieb
I am working on an application that needs to parse out data that has
been copied into the clipboard. My first questions are how can I
detect if the clipboard is empty,
dim do as Dataobject
do = Clipboard.GetDataObject
if do.getformats.length = 0
MessageBox.Show("Clipboard is empty")
else
'...
end if

and how can I empty the clipboard?
Clipboard.SetDataObject(New DataObject)
I tried the code below, but it didn't seem to tell me if the
clipboard was empty.
If Clipboard.GetDataObject() Is Nothing Then
MessageBox.Show("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDataObject()
If (txtdata.GetDataPresent(DataFormats.Text)) Then
MessageBox.Show(txtdata.GetData(DataFormats.Text))
End If
End If

Also, the data that is being copied is basically a 8000 line
document containing data plots from an instrument in our labs. I
need to grab certain data from the third line. Any suggestions on
how to do this?


Dim txtdata As IDataObject = Clipboard.GetDataObject()
If txtdata.GetDataPresent(DataFormats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtdata.GetData(DataFormats.Text), String)
lines = Strings.Split(s, vbCrLf)
MsgBox(lines(2))
End If
--
Armin

Nov 20 '05 #2

P: n/a
Wow...thanks a lot!

One more question: how would I save the contents to a text file?


"Armin Zingler" <az*******@freenet.de> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
"Joshua Campbell" <Jo*************@WellmanInc-DieSpamDie.com>
schrieb
I am working on an application that needs to parse out data that has
been copied into the clipboard. My first questions are how can I
detect if the clipboard is empty,


dim do as Dataobject
do = Clipboard.GetDataObject
if do.getformats.length = 0
MessageBox.Show("Clipboard is empty")
else
'...
end if

and how can I empty the clipboard?


Clipboard.SetDataObject(New DataObject)
I tried the code below, but it didn't seem to tell me if the
clipboard was empty.
If Clipboard.GetDataObject() Is Nothing Then
MessageBox.Show("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDataObject()
If (txtdata.GetDataPresent(DataFormats.Text)) Then
MessageBox.Show(txtdata.GetData(DataFormats.Text))
End If
End If

Also, the data that is being copied is basically a 8000 line
document containing data plots from an instrument in our labs. I
need to grab certain data from the third line. Any suggestions on
how to do this?


Dim txtdata As IDataObject = Clipboard.GetDataObject()
If txtdata.GetDataPresent(DataFormats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtdata.GetData(DataFormats.Text), String)
lines = Strings.Split(s, vbCrLf)
MsgBox(lines(2))
End If
--
Armin

Nov 20 '05 #3

P: n/a
"Joshua Campbell" <Jo*************@WellmanInc-DieSpamDie.com> schrieb

Dim txtdata As IDataObject = Clipboard.GetDataObject()
If txtdata.GetDataPresent(DataFormats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtdata.GetData(DataFormats.Text),
String) lines = Strings.Split(s, vbCrLf)
MsgBox(lines(2))
End If


Wow...thanks a lot!

One more question: how would I save the contents to a text file?


imports sytem.io

'...

Dim fs as filestream
dim sw as streamwriter

fs = new filestream("test.txt", _
"", FileMode.CreateNew, FileAccess.Write, FileShare.Read _
)

sw = new StreamWriter(fs, System.Text.Encoding.Default)
sw.write(s) 's is the variable from the first example
sw.close
The streamwriter uses UTF8 encoding by default. Specifying
System.Text.Encoding.Default uses ANSI-Encoding. You can also use
System.Text.Encoding.Unicode and other encodings.
see also:

<F1>
Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Visual Basic Language Tour
-> Processing drives, folders and files
.NET Framework
Programming with .NET Framework
-> Working with I/O

(see hints in signature)
--
Armin

- The tree representing the table of contents has been translated from
localized (German) version. Excuse slight deviations.

Nov 20 '05 #4

P: n/a
I have some playing to do with the filestream, but this definately gets me
working! Thank you very much!!!

Joshua
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.