Solved

Copy Text From RichTextBox

Posted on 2003-10-21
10
244 Views
Last Modified: 2010-05-03
I am trying to make a commandbutton (Called Copy) when clicked copy text from a RichTextBox (Called RTB)
But...
A) If no text is selected it selects and copies all the text in the RTB
B) If some text is selected it coped only the selected text.
0
Comment
Question by:neutrinohunter
  • 5
  • 4
10 Comments
 
LVL 2

Assisted Solution

by:Djinn_ro
Djinn_ro earned 20 total points
ID: 9593893
??????
Use RTB.SelLength
If RTB.SelLength=0 then
   'no text is select
   YourString=RTB.Text
Else
   'nr of char of selected text
   YourString=RTB.SelText
End if
0
 

Author Comment

by:neutrinohunter
ID: 9594063
Sorry I must have been very unclear in my post.

What I meant was I am trying to copy the text from a RichTextBox
But the code I am using seems to work only for textboxes. Thus it aint copying any text.

So if someone could post a code to Copy the text aswell as select the text as Djinn_ro posted that would be gr8

Thx
0
 
LVL 4

Expert Comment

by:eric0213
ID: 9594889
If RTB.SelLength=0 then
   'no text is select
   YourString=RTB.Text
Else
   'nr of char of selected text
   YourString=RTB.SelText
End if

Clipboard.Clear
Clipboard.SetText = YourString

' If you accept this, give the points to Djinn_ro
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:neutrinohunter
ID: 9597581
k, but what does YourString mean?

I pasted all that in my code, but it says
Variable Not defined?
0
 
LVL 4

Expert Comment

by:eric0213
ID: 9598565
define the variable...

Dim YourString As String
0
 

Author Comment

by:neutrinohunter
ID: 9598961
I tried that.

Its says
Compile Error;
Argument not optional


? Help Please.
0
 
LVL 4

Expert Comment

by:eric0213
ID: 9598970
what argument?  what line?
0
 

Author Comment

by:neutrinohunter
ID: 9599460
This line
Clipboard.SetText = YourString
0
 
LVL 4

Accepted Solution

by:
eric0213 earned 20 total points
ID: 9599590
oops :(  sorry about that...

' can't use vbCFRTF constant because of Microsoft bug
' vbCFRTF is stored as a long, but SetText expects an Integer
' and an overflow is caused
Private Sub cmdCopyRTF_Click()
    Clipboard.Clear
   
    If RTB.SelLength = 0 Then
        Clipboard.SetText RTB.TextRTF, &HBF01
    Else
        Clipboard.SetText RTB.SelRTF, &HBF01
    End If
End Sub

Private Sub cmdCopyText_Click()
    Clipboard.Clear
   
    If RTB.SelLength = 0 Then
        Clipboard.SetText RTB.Text, vbCFText
    Else
        Clipboard.SetText RTB.SelText, vbCFText
    End If
End Sub
0
 
LVL 4

Expert Comment

by:eric0213
ID: 9599593
There's two choices... one that copies text and one that copies rtf text
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question