Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Saving the content of the clipboard and restoring it in VB

Posted on 2004-04-16
9
225 Views
Last Modified: 2010-05-02
Hi I wrote a program which uses the clipboard. But I dont want to loose the content that was in the clipboard before i used it..
I have checked everywhere on the net to find a sample program that can save no matter what from the clipboard and restore it to the clipboard afterwards. I have found some that can save and restore some things like text pictures etc. but they were not ble to save everything.


So if there is anybody who is able to write a function that can do that. id be very thankful.
0
Comment
Question by:AIDeton
  • 4
  • 3
9 Comments
 
LVL 6

Expert Comment

by:mmusante
ID: 10843459
I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

Temp = Clipboard.GetText(vbCFText)
Open app.path & "\Clip.txt" For Output As #1
Print #1, Temp
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10848550
>> I think you can use the 'GetText' method of the clipboard object and then save it to a file ...

GetText is for Text only and won't apply to objects.


>> So if there is anybody who is able to write a function that can do that. id be very thankful.

http://www.vb-helper.com/howto_track_clipboard.html

The above is a start on how to go about it. Main reason for the link is to take note on how to Get/Set "File Lists" (when you select files in Explorer and chose "copy").

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp?frame=true

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardoperations.asp?frame=true


The above provide information on the formats and operations. Pay attention to how the clipboard data is stored for different formats and how it is suggested to go about retrieving the data... (quote below).

"To retrieve paste information from the clipboard, a window first determines the clipboard format to retrieve. Typically, a window enumerates the available clipboard formats by using the EnumClipboardFormats function and uses the first format it recognizes. This method selects the best available format according to the priority set when the data was placed on the clipboard."
0
 

Author Comment

by:AIDeton
ID: 10906976
hey zzzzzooc,
the program from vb-helper seems to be exactly whyt I need. unfortunately I do not seem to have the knowlege on how to use the clipboardsetfiles() function. i do not know what i have to give it as parameter. it says something like an arrey file_names().
I have already tried some things but nothing seems to be working.

and I cant see how it is used because the function is in the exampleprogram but not used at all.

I'd be glad If you could explain to me how i have to use it.

thanks for your help
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:AIDeton
ID: 10963772
Hey guys I really need your help I would appreciate if you could tell me how to use the restore function.
I am in a lot time pressure so i will increase the points(250-350) hopeing that you will help me then.

Thank You
AIDeton
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 total points
ID: 11258790
Sorry, an overlooked question.

It's most-likely too late and I apologize but all you had to do was pass an array populated with file-names to the function such as:

    Dim MyArray(2) As String
    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"
    Call ClipboardSetFiles(MyArray)


My suggestion for the question is either accept answer / PAQ & refund.
0
 

Author Comment

by:AIDeton
ID: 11287746
yeah it is a little bit late but we cant change that. thank you anyways that you answered the question i dont have time to test the code but i will next week or so...
here are the points.

AIDeton
0
 

Author Comment

by:AIDeton
ID: 11350956
Hi Zzzzzzooc,
I know i am kinda late with this and that i have already accepted your answere but i have a lil problem... I foudn time today to try out the function you gave me. the problem is when i add your code to a function it will write c:\test1.txt
3 times into the clipboard. I mean okay now i know howto write text into the clipboard but i need to write the data back into the clipboard that had been there shortly before, which can be everything... maybe contacting each other would be easier if we exchanged e mail adresses or ICQ#. I promise i will give you further points if you help me solve this problem.
It is still very important for me to solve/ understand this problem.

AIDeton
ICQ: 110093435
Email: simon@simonweiss.de
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 11352705
It's best to keep any help provided here.

ClipboardSetFiles() sets every item in the array into the clipboard.

    MyArray(0) = "c:\test1.txt"
    MyArray(1) = "c:\test1.txt"
    MyArray(2) = "c:\test1.txt"

Since there are 3 items in the clipboard, all 3 will be copied to the clipboard. If you removed MyArray(1) and MyArray(2), only one would be copied to the clipboard.

The function ClipboardGetFiles() returns an array such as MyArray() with all of the items from the clipboard. All you would need to do is pass the array from ClipboardGetFiles() to ClipboardSetFiles(). I hope that's enough to resolve that.

Since it seems you aren't too familiar with all of the aspects of VB, you may want to search Yahoo! for tutorials/guides or buy/read books.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question