|
-
Jul 9th, 2004, 01:33 AM
#1
Thread Starter
Lively Member
Copying & Pasting code
OK, so somer of you may remember me from about the end of last year when I was working on a project. I've got version 1.0 in production, and am currently working on new features that they have asked for in version 1.1.
I've worked many of them out, but have a question. OK, so what I need to do is have buttons on the toolbar that find out what text is selected and copy it to the clipaboard, and also paste that text in at the current cursor location.
I know in textboxes that they can just right-click, or use keyboard shortcuts (CTRL+C and CTRL+V), but as these are automatically done by Windows/VB, I'm at a loss as to how it should be done. It's probably very simple, but I just can't think of how it's done.
-
Jul 9th, 2004, 01:49 AM
#2
Hyperactive Member
VB Code:
'// - Copy
Clipboard.SetText txt.SelText
'// - Paste
txt.SelText = Clipboard.GetText
Born to help others
(If I've been helpful then please rate my post. Thanks)
call me EJ or be slapped! 
-
Jul 9th, 2004, 01:52 AM
#3
Thread Starter
Lively Member
Thanks very much for that. I'll give it a try. I thought it would have been easier than I first suspected.
Weird! The code I'm using is:
VB Code:
If Button = "Paste" Then
txt.SelText = Clipboard.GetText
End If
When that code executes, I get a Run-Time Error: Object Required?!?!
Correction: I get the same for both of them, they are both activated through toolbars. I've had a thought - maybe because the toolbar button is the active object when you click, that may be causing the whole thing to get confused?
Last edited by dogwomble; Jul 9th, 2004 at 02:01 AM.
-
Jul 9th, 2004, 02:17 AM
#4
Hyperactive Member
Try this code
VB Code:
Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
On Error Resume Next
Select Case Button.Key
Case "Copy"
'- Copy Code
Case "Paste"
'- Paste Code
End Select
End Sub
Last edited by EJ12N; Jul 9th, 2004 at 02:24 AM.
Born to help others
(If I've been helpful then please rate my post. Thanks)
call me EJ or be slapped! 
-
Jul 9th, 2004, 03:44 AM
#5
Thread Starter
Lively Member
With the "on error resume next" in there, the copy&paste code does nothing. WIthout the on error resume next, I get the same error.
-
Jul 9th, 2004, 03:52 AM
#6
Hyperactive Member
weird works for me...
make sure in properties of toolbar buttons got key name
Copy, Paste key names then do the code i told you above should work...
Born to help others
(If I've been helpful then please rate my post. Thanks)
call me EJ or be slapped! 
-
Jul 10th, 2004, 09:39 AM
#7
Thread Starter
Lively Member
It's getting the name OK. All the other buttons work. Here's the problem code:
VB Code:
On Error Resume Next
Select Case Button
Case "Copy"
Clipboard.SetText txt.SelText
Case "Paste"
txt.SelText = Clipboard.GetText
Case "Enter Resident"
frmtblClientInfo.Show
Case "Modify Resident"
frmQueryGetInfo.Show
Case "Single Resident Report"
frmSingleResident.Show
Case "All Residents Report"
mnuAllResidentsReport_Click
Case "Quit"
Unload Me
Case "Help"
frmAbout.Show vbModal, Me
End Select
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|