Solved

Copy Text From RichTextBox

Posted on 2003-10-21
10
242 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now