Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Copy Text From RichTextBox

Posted on 2003-10-21
10
Medium Priority
?
253 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 60 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 60 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

783 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