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.
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.
To get the clipboard content, try
vb Code:
Dim s As String s = Clipboard.GetText(vbCFText) MsgBox s
Welcome to the forumsWhat highlighted text? Where is it highlighted?Originally Posted by argiejulaton
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.
Please use [Code]your code goes in here[/Code] tags when posting code.
When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.
Creating A Wizard In VB.NET
Paging A Recordset
What is wrong with using On Error Resume Next
Good Article: Language Enhancements In Visual Basic 2010
Upgrading VB6 Code To VB.NET
Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked
Nothing get's automatically stored into value, you'll have to do that yourself:
Get the selected text into clipboard:
get Clipboard text into variable:Code:Call Clipboard.clear call Clipboard.SetText(mid$(Textbox1.Text, Textbox1.SelStart, Textbox1.SelLength))
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:Dim s as string s = Clipboard.GetText
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.
is the web browser in your program, or some other program?For example i'm now using a web browser
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
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).
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.
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:
Option Explicit Private Const VK_LBUTTON = &H1 Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI) As Long Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Function GetSelectedText() As String Dim htmlDoc As HTMLDocument Dim htmlRange As IHTMLTxtRange Dim SelectedText As String Set htmlDoc = WebBrowser1.Document Set htmlRange = htmlDoc.selection.createRange GetSelectedText = htmlRange.Text End Function Private Sub Form_Load() WebBrowser1.Navigate "www.google.com" Timer1.Interval = 200 Timer1.Enabled = False End Sub Private Sub Timer1_Timer() Static MousePos As POINTAPI Static Holding As Boolean Static PrevX As Long GetCursorPos MousePos Select Case GetAsyncKeyState(VK_LBUTTON) Case 0 'Released Holding = False Case Is <> 0 'Down If Holding = True And MousePos.X <> PrevX Then Clipboard.SetText GetSelectedText Holding = False End If Holding = True PrevX = MousePos.X End Select End Sub Private Sub Web1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Timer1.Enabled = True End Sub
to use just select any text anywhere on webbrowser and it will be copied to your clipboard (right mouse click - Paste)