473,657 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with clipboard

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.GetDa taObject() Is Nothing Then
MessageBox.Show ("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDa taObject()
If (txtdata.GetDat aPresent(DataFo rmats.Text)) Then
MessageBox.Show (txtdata.GetDat a(DataFormats.T ext))
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
4 6595
"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.GetDa taObject
if do.getformats.l ength = 0
MessageBox.Show ("Clipboard is empty")
else
'...
end if

and how can I empty the clipboard?
Clipboard.SetDa taObject(New DataObject)
I tried the code below, but it didn't seem to tell me if the
clipboard was empty.
If Clipboard.GetDa taObject() Is Nothing Then
MessageBox.Show ("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDa taObject()
If (txtdata.GetDat aPresent(DataFo rmats.Text)) Then
MessageBox.Show (txtdata.GetDat a(DataFormats.T ext))
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.GetDa taObject()
If txtdata.GetData Present(DataFor mats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtd ata.GetData(Dat aFormats.Text), String)
lines = Strings.Split(s , vbCrLf)
MsgBox(lines(2) )
End If
--
Armin

Nov 20 '05 #2
Wow...thanks a lot!

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


"Armin Zingler" <az*******@free net.de> wrote in message
news:er******** ******@TK2MSFTN GP12.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.GetDa taObject
if do.getformats.l ength = 0
MessageBox.Show ("Clipboard is empty")
else
'...
end if

and how can I empty the clipboard?


Clipboard.SetDa taObject(New DataObject)
I tried the code below, but it didn't seem to tell me if the
clipboard was empty.
If Clipboard.GetDa taObject() Is Nothing Then
MessageBox.Show ("Clipboard is empty")
Else
Dim txtdata As IDataObject = Clipboard.GetDa taObject()
If (txtdata.GetDat aPresent(DataFo rmats.Text)) Then
MessageBox.Show (txtdata.GetDat a(DataFormats.T ext))
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.GetDa taObject()
If txtdata.GetData Present(DataFor mats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtd ata.GetData(Dat aFormats.Text), String)
lines = Strings.Split(s , vbCrLf)
MsgBox(lines(2) )
End If
--
Armin

Nov 20 '05 #3
"Joshua Campbell" <Jo************ *@WellmanInc-DieSpamDie.com> schrieb

Dim txtdata As IDataObject = Clipboard.GetDa taObject()
If txtdata.GetData Present(DataFor mats.Text) Then
Dim s As String
Dim lines As String()
s = DirectCast(txtd ata.GetData(Dat aFormats.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("tes t.txt", _
"", FileMode.Create New, FileAccess.Writ e, FileShare.Read _
)

sw = new StreamWriter(fs , System.Text.Enc oding.Default)
sw.write(s) 's is the variable from the first example
sw.close
The streamwriter uses UTF8 encoding by default. Specifying
System.Text.Enc oding.Default uses ANSI-Encoding. You can also use
System.Text.Enc oding.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
11466
by: LG | last post by:
Just have a question with regards to the clipboard, and how to read what other applications (Adobe InDesignCS) place in the clipboard. I am currently in the process of creating a booklet from a database, and I need the data to be laid out in a tabular format, and set out in a specific way. At the current point in time, I am copy/pasting the raw text from the database into a table layout in InDesign. What I was thinking is that if I could...
2
2299
by: Wayne Wengert | last post by:
I am trying to copy the text from a textbox to the clipboard. I saw some code posted earlier for Pasting from the clipboard so I modified it for copy but it is not working (see code below). When I click on the btnCopyToClipboard I can see some processing going on but the text from the textbox is not being put on the clipboard? Thoughts or suggestions? Wayne
4
1245
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to code an event and seem to be stuck on something that might seem pretty simple (I am a newbie...) I have two textboxes on a form, I have a button on a form that is supposed to copy selected text. When I click the button I want the selected text to be copied into the clipboard. I can do this by saying: Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As
7
3842
by: Newbie | last post by:
How do I clear the clipboard in VB.NET 2003? TIA Newbie
14
4364
by: ldpfrog | last post by:
I posted a few weeks ago about an encryption program I was writing. I now have it working almost as a translator program. I want to use system wide hotkeys to be able to copy, run through the scrambler, and paste over wherever the text was, while also continue to add to the log kept in the home form. I am using mclhotkey for the systemwide hotkeys, but I am not familiar with the clipboard in VB6. This is the code I have to encode whatever...
15
12285
by: Peter Duniho | last post by:
I'm trying to use .NET and C# to draw a metafile copied to the clipboard by another application (Word 2003 in this case, but it shouldn't matter). I naively thought that I'd be able to use the Clipboard class to get an EnhancedMetafile or MetafilePict object from the Clipboard, use that to create a new Metafile object, and then draw that Metafile object using Graphics.DrawImage. It doesn't seem to be that simple.
1
18648
by: Figmo | last post by:
Wow.....this is darned odd.... I have an app that integrates with other applications. It registers a global hotkey with Windows. When the hotkey executes it sends a CTRL-C to the active window (any application) to copy whatever text is selected to the clipboard. It then issues a C# Clipboard.GetText(...) and does some processing with this string. All is good, no errors thus far.
8
2489
by: active | last post by:
Guess I'm looking for someone who likes to work difficult puzzles. I can't seem to ever retrieve a palette handle from the clipboard. Below is a simple test program that demonstrates the problem. The program uses windows api to get a handle to a palette from the clipboard. The palette needs to be put there by another program - maybe Photoshop.
20
6992
by: Joe Duchtel | last post by:
Hello - I have the following code to get a bitmap from the clipboard and to save it to a *.png file ... Dim lData As IDataObject = Clipboard.GetDataObject() If lData.GetDataPresent(DataFormats.Bitmap) Then Dim lPictureBox As New PictureBox
0
8306
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6164
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.