Copy-Paste Sample in Visual Basic 6


This is a copy paste sample in Visual Basic 6. It shows you how to use the clipboard object in VB6 to perform copy paste operations in your application. This is a very easy sample targeted to the beginners. It shows you the use of the clipboard object very simply and in a straightforward way avoiding the complexities related to this object. Of course, you can make a complex program using the Clipboard object to achieve something of a very high level. 

Let me describe you the interface of this sample application. This sample contains only one form. There are two TextBox controls. Text strings are copied from one TextBox and pasted to another. Finally there are two CommandButton controls - one for copying and another for pasting.
Names of the controls:
txtCopy
txtPaste
cmdCopy
cmdPaste


Learn about:

As you can see from the screenshot below, the cmdCopy CommandButton is used to copy text from the txtCopy (the user must first write something in the TextBox txtCopy). On other hand, the cmdPaste CommandButton is used to paste the text to the txtPaste TextBox.

Now comes the "how to do this" part in your code. Two methods of Clipboard have been used. They are - SetText and GetTex. The SetText method puts the text string on the Clipboard object while the GetText method returns a text string from the Clipboard object.
Screenshot:




Code:
Private Sub cmdCopy_Click()
    Clipboard.SetText (txtCopy.Text)
End Sub
________________________________________
Private Sub cmdPaste_Click()
    txtPaste.Text = Clipboard.GetText
End Sub