Monday, May 24, 2010

What do I need to know to create a memory resident program with Visual Basic?

.


Specifically, I want to create a memory resident program which will do a COPY to the Clipboard by **merely highlighting** text (ready to PASTE) without the need for CTRL-C.





Background: Many years of programming, but fairly new to VB.


Additional question: is there an existing freeware utility for the above? (I wish to learn about mem resident programming in VB regardless).





TIA! :)


Ballpeen

What do I need to know to create a memory resident program with Visual Basic?
If you intend to capture text from other applications (this is why you probably refer to mem resident), I don't think it can be done at all, certainly not VB.


The closest would be that you have an background app that monitors whether Shift is held down, then checks the active window and sees what is selected. This will work fine for text boxes and maybe a set of other controls, but to support other sources as Word, Excel etc you would need a HUGE select case. I'd recommend only VC++ for the purpose, VB would be a bottleneck for the system.
Reply:There is a way in VB to copy the highlighted text to the clipboard. Here are some code that might be useful for you:





Sub Main()


Dim myString As String


myString = "1234" // This can be your highlighted text


//Clear the contents of the Clipboard.


Clipboard.Clear


// Copy selected text to Clipboard.


Clipboard.SetText myString


End Sub





Of you can use the following piece of code:


Sub mnuCut_Click ()


' empty the clipboard


Clipboard.Clear


' copy the selected text to the clipboard


Clipboard.SetText txtBox.SelText


' and remove the selected text


txtBox.SelText = ""


End Sub





Sub mnuCopy_Click ()


' empty the clipboard


Clipboard.Clear


' and copy the selected text to the clipboard


Clipboard.SetText txtBox.SelText


End Sub





Sub mnuPaste_Click ()


' paste clipboad text into document


txtBox.SelText = Clipboard.GetText()


End Sub





Hope this helps


No comments:

Post a Comment