Results 1 to 7 of 7

Thread: Copying & Pasting code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    98

    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.

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    VB Code:
    1. '// - Copy
    2. Clipboard.SetText txt.SelText
    3. '// - Paste
    4. 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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    98
    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:
    1. If Button = "Paste" Then
    2.         txt.SelText = Clipboard.GetText
    3.     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.

  4. #4
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    Try this code
    VB Code:
    1. Private Sub tbToolBar_ButtonClick(ByVal Button As MSComCtlLib.Button)
    2.     On Error Resume Next
    3.     Select Case Button.Key
    4.         Case "Copy"
    5.             '- Copy Code
    6.         Case "Paste"
    7.             '- Paste Code
    8.      End Select
    9. 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!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    98

    Thumbs down

    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.

  6. #6
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    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!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Posts
    98
    It's getting the name OK. All the other buttons work. Here's the problem code:

    VB Code:
    1. On Error Resume Next
    2.     Select Case Button
    3.          Case "Copy"
    4.             Clipboard.SetText txt.SelText
    5.         Case "Paste"
    6.             txt.SelText = Clipboard.GetText
    7.         Case "Enter Resident"
    8.             frmtblClientInfo.Show
    9.         Case "Modify Resident"
    10.             frmQueryGetInfo.Show
    11.         Case "Single Resident Report"
    12.             frmSingleResident.Show
    13.         Case "All Residents Report"
    14.             mnuAllResidentsReport_Click
    15.         Case "Quit"
    16.             Unload Me
    17.         Case "Help"
    18.             frmAbout.Show vbModal, Me
    19.         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
  •  



Click Here to Expand Forum to Full Width