Results 1 to 19 of 19

Thread: How to copy selected text

  1. #1

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467

    How to copy selected text

    hi everybody
    I am writing a function which will display the details of a keyword
    which is selected from particular textbox by double clicking on the
    text box.

    My problem is, when i try to use the SelText property, it returns a
    blank string. I have observed that when i double click on the text
    box on particular word, it gets selected automatically but i can't
    process that text in dblClick event of the text box(as i mentioned,
    Seltext returns "").
    How can i copy the selected text somewhere?
    Please help!!

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Is the 'selected' text user selected, or is it always fixed in the TextBox.
    ________
    AROMED VAPORIZERS
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:54 AM.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Try:
    VB Code:
    1. Option Explicit
    2. Dim sTemp As String
    3.  
    4. Private Sub Text1_LostFocus()
    5.     sTemp = Text1.SelText
    6. End Sub
    7.  
    8. Private Sub Text2_DblClick()
    9.     Text2.Text = sTemp
    10. End Sub
    ________
    WildCATblond
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:54 AM.

  4. #4

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by Bruce Fox
    Is the 'selected' text user selected, or is it always fixed in the TextBox.
    No. Selected text is not the text selected by user. It is the text
    which gets selected when user double clicks on any text.(Try it on
    any text on this page.)
    i want the word which gets selected by double clicking.
    And it is not fixed also.

  5. #5

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by Bruce Fox
    Try:
    VB Code:
    1. Option Explicit
    2. Dim sTemp As String
    3.  
    4. Private Sub Text1_LostFocus()
    5.     sTemp = Text1.SelText
    6. End Sub
    7.  
    8. Private Sub Text2_DblClick()
    9.     Text2.Text = sTemp
    10. End Sub
    No bruce Fox,
    I dont want this.
    i want it done while the focus is in the textbox only.

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Hmmm, is there an API?
    ________
    Silversurfer reviews
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:55 AM.

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    I think I may have... hang on

  8. #8
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Use this:


    Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then me.Caption = Text1.SelText
    End Sub
    Leather Face is comin...


    MCSD

  9. #9
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Is this what you wanted?

    VB Code:
    1. Private Sub Text1_DblClick()
    2.   lblText.Caption = Text1.SelText
    3. End Sub

  10. #10

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by Harddisk
    Is this what you wanted?

    VB Code:
    1. Private Sub Text1_DblClick()
    2.   lblText.Caption = Text1.SelText
    3. End Sub
    Yes this is what i want. And this works with normal textbox.
    Unfortunately it seems that is doesn't work with Microsoft Forms 2.0 textbox
    I am using it to display japanese characters
    Thanks for the help!

  11. #11
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    I know this has the same effect as Text1.SelText, however,
    in your case will this return the char string ur after?
    VB Code:
    1. Private Sub Text1_DblClick()
    2. Dim sText As String
    3.  
    4.     sText = Mid$(Text1.Text, Text1.SelStart, Text1.SelLength + 1)
    5.  
    6.     MsgBox sText
    7.  
    8. End Sub
    ________
    Housewives live
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:55 AM.

  12. #12

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Hi Bruce Fox
    In method you have suggested, i am getting SelLength = 0.
    It seems that the text gets selected after double click.

  13. #13
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Hmmmm,

    Thats interesting, It works fine on a Form with aText1 for me.
    I guess MSForms 2.0 may be different!

    edit: - Just tested and your right.

    MS Forms 2.0 TextBox1 won't work the same way

    Bruce.
    ________
    01SmilyBlonde
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:55 AM.

  14. #14
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    That is why you should use the mouse up event..


    Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then me.Caption = Text1.SelText
    End Sub
    Leather Face is comin...


    MCSD

  15. #15
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Leather, did you test that in an MS Forms 2.0 TextBox1?
    ________
    Washington Dispensaries
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:55 AM.

  16. #16
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Sorry Leather,

    It test out fine on a MS Forms 2.0 TextBox1
    ________
    LIVE SEX WEBSHOWS
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:56 AM.

  17. #17
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    No worries..
    Leather Face is comin...


    MCSD

  18. #18
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Yeh, those bloody "MS Forms TextBox's" must 'fire' differently to
    the good ol Text1.

    Bruce.
    ________
    XSexyKittenX
    Last edited by Bruce Fox; Aug 14th, 2011 at 04:56 AM.

  19. #19

    Thread Starter
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Hi Leather
    Method you suggested fires 2 times for a double click.(MouseUp)
    For MS Forms 2.0 textbox, text gets selected but I could not
    display it using your method.
    If you know 'Microsoft Bookshelf Basics' (it comes with Office 97),
    it has this capability to display Japanese text and also display the details of selected word.
    Well...let me know if you come up with something
    Thanks for the help anyway.

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