|
-
Jul 19th, 2012, 05:40 AM
#1
Thread Starter
New Member
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.
-
Jul 19th, 2012, 06:09 AM
#2
Re: Clipboard Select Event HELP!
To get the clipboard content, try
vb Code:
Dim s As String s = Clipboard.GetText(vbCFText) MsgBox s
-
Jul 19th, 2012, 06:11 AM
#3
Re: Clipboard Select Event HELP!
Welcome to the forums 
 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.
-
Jul 19th, 2012, 06:26 AM
#4
Thread Starter
New Member
Re: Clipboard Select Event HELP!
 Originally Posted by Hack
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.
-
Jul 20th, 2012, 08:11 AM
#5
Hyperactive Member
Re: Clipboard Select Event HELP!
 Originally Posted by argiejulaton
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)
-
Jul 22nd, 2012, 02:54 AM
#6
Thread Starter
New Member
Re: Clipboard Select Event HELP!
 Originally Posted by SuperDre
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.
-
Jul 22nd, 2012, 03:15 AM
#7
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
-
Jul 22nd, 2012, 02:10 PM
#8
Hyperactive Member
Re: Clipboard Select Event HELP!
 Originally Posted by argiejulaton
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).
-
Jul 22nd, 2012, 02:15 PM
#9
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.
-
Jul 23rd, 2012, 05:44 PM
#10
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:
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
-
Jul 23rd, 2012, 05:45 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|