Results 1 to 11 of 11

Thread: Clipboard Select Event HELP!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    7

    Post Clipboard Select Event HELP!

    Hello. I'm asking on how to use the clipboard select event in vb6 to get the value of the highlighted text and put it in a variable; to display the text in a msgbox. please help me. i'm new in vb6 programming.

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Clipboard Select Event HELP!

    To get the clipboard content, try
    vb Code:
    1. Dim s As String
    2.     s = Clipboard.GetText(vbCFText)
    3.     MsgBox s



  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Clipboard Select Event HELP!

    Welcome to the forums
    Quote Originally Posted by argiejulaton
    to get the value of the highlighted text
    What highlighted text? Where is it highlighted?

    There are built in VB6 functions that deal with storing and retriving data from the clipboard object:
    Clipboard.GetText - retrieves text from the clipboard
    Clipboard.SetText - puts text on the clipboard

    Without more details on what you are doing and how you are doing it, thats the best I can do.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    7

    Re: Clipboard Select Event HELP!

    Quote Originally Posted by Hack View Post
    Welcome to the forums What highlighted text? Where is it highlighted?

    There are built in VB6 functions that deal with storing and retriving data from the clipboard object:
    Clipboard.GetText - retrieves text from the clipboard
    Clipboard.SetText - puts text on the clipboard

    Without more details on what you are doing and how you are doing it, thats the best I can do.
    oh! thank you what i mean is when you highlight a text it's automatically store the value of the highlighted in a variable.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    264

    Re: Clipboard Select Event HELP!

    Quote Originally Posted by argiejulaton View Post
    oh! thank you what i mean is when you highlight a text it's automatically store the value of the highlighted in a variable.
    Nothing get's automatically stored into value, you'll have to do that yourself:

    Get the selected text into clipboard:
    Code:
    Call Clipboard.clear
    call Clipboard.SetText(mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength))
    get Clipboard text into variable:
    Code:
    Dim s as string
    s = Clipboard.GetText
    Ofcourse if you just need the highlighted text into a mesagebox/variable and you are on the form where the textbox is, you'll just use:
    Code:
    call MsgBox(mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength))
    
    Dim s as string 
    s = mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength)

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    7

    Re: Clipboard Select Event HELP!

    Quote Originally Posted by SuperDre View Post
    Nothing get's automatically stored into value, you'll have to do that yourself:

    Get the selected text into clipboard:
    Code:
    Call Clipboard.clear
    call Clipboard.SetText(mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength))
    get Clipboard text into variable:
    Code:
    Dim s as string
    s = Clipboard.GetText


    Ofcourse if you just need the highlighted text into a mesagebox/variable and you are on the form where the textbox is, you'll just use:
    Code:
    call MsgBox(mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength))
    
    Dim s as string 
    s = mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength)
    i'm asking for help; is it possible to get the data of a selected/highlighted text by just highlighting it. For example i'm now using a web browser and i want to copy a text from it. So from that the data of highlighted text will be stored in a variable. From that i'm just gonna use the variable for displaying purposes.

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Clipboard Select Event HELP!

    For example i'm now using a web browser
    is the web browser in your program, or some other program?

    it would appear that this question is not about the clipboard at all, more likely about textbox selected text in other program
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Hyperactive Member
    Join Date
    Mar 2009
    Posts
    264

    Re: Clipboard Select Event HELP!

    Quote Originally Posted by argiejulaton View Post
    i'm asking for help; is it possible to get the data of a selected/highlighted text by just highlighting it. For example i'm now using a web browser and i want to copy a text from it. So from that the data of highlighted text will be stored in a variable. From that i'm just gonna use the variable for displaying purposes.
    It is possible but certainly not easy (if you are talking about webbrowser as in a separate application), but since you're asking this I don't think it's up your level of programming (not to put you down or something, but to accomplish something like you'll need to use the WinAPI and a lot of time), even then it might not even be possible. If it's using the webbrowser component in your own application than it's much easier (if I'm not mistaken).

  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Clipboard Select Event HELP!

    The clipboard is meant to be user-directed.

    I'm not sure why you'd think it makes sense for Windows to broadcast "Hey, there is something new selected somewhere" to every running program. For that matter a user might be running 18 different programs for different things and doing copy/paste all over for various purposes.

    You might want to rethink the premise of this whole thing.

  10. #10
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Clipboard Select Event HELP!

    i totally agree with dilettante but here is a sample you can use or change to your needs

    add a timer "Timer1" and a webbrowser "WebBrowser1"
    vb Code:
    1. Option Explicit
    2.  
    3.  
    4.  Private Const VK_LBUTTON = &H1
    5.  
    6.  Private Type POINTAPI
    7.     X As Long
    8.     Y As Long
    9.  End Type
    10.  
    11. Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) As Long
    12. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    13.  
    14.  
    15.  
    16. Private Function GetSelectedText() As String
    17.  Dim htmlDoc As HTMLDocument
    18.  Dim htmlRange As IHTMLTxtRange
    19.  Dim SelectedText As String
    20.  
    21.    Set htmlDoc = WebBrowser1.Document
    22.    Set htmlRange = htmlDoc.selection.createRange
    23.  
    24.  GetSelectedText = htmlRange.Text
    25. End Function
    26.  
    27.  
    28. Private Sub Form_Load()
    29. WebBrowser1.Navigate "www.google.com"
    30. Timer1.Interval = 200
    31. Timer1.Enabled = False
    32. End Sub
    33.  
    34. Private Sub Timer1_Timer()
    35. Static MousePos As POINTAPI
    36. Static Holding As Boolean
    37. Static PrevX As Long
    38.  
    39. GetCursorPos MousePos
    40.  
    41. Select Case GetAsyncKeyState(VK_LBUTTON)
    42.  
    43.    Case 0 'Released
    44.       Holding = False
    45.    Case Is <> 0 'Down
    46.       If Holding = True And MousePos.X <> PrevX Then
    47.          Clipboard.SetText GetSelectedText
    48.          Holding = False
    49.       End If
    50.     Holding = True
    51.     PrevX = MousePos.X
    52. End Select
    53.  
    54. End Sub
    55.  
    56. Private Sub Web1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    57. Timer1.Enabled = True
    58. End Sub

  11. #11
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Clipboard Select Event HELP!

    to use just select any text anywhere on webbrowser and it will be copied to your clipboard (right mouse click - Paste)

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