Link to home
Start Free TrialLog in
Avatar of vip110598
vip110598

asked on

Adding a custom value to selected lines


Please help,
I am useing a RichTextBox control and would like to be
able to select 5 or 6 lines of text, click a command
button and for the selection to process the following.

For the lines selected, I would like to add a word or number
at the end of each line selected.

If this was the selected text... and VIP was the word to
add..

for each line given VIP
like in this VIP
little example, VIP
I have the word VIP displayed. VIP

Get the idea?

Please, show me how to add a word at the end of each line
selected please detail how this function could be used to
add a word at the begining of each line.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Inteqam
Inteqam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Inteqam
Inteqam

this is a better answer to use to add to both : end and begining:

Private Sub Command1_Click()
    Dim n As Integer
    Dim c As String
    Dim sel As String
    Dim try As String
    Dim b As Boolean
   
    try = ""
    b = False
    If Me.RichTextBox1.SelLength > 0 Then
        sel = Me.RichTextBox1.SelText
        For n = 1 To Me.RichTextBox1.SelLength
            c = Mid(sel, n, 1)
           
            If b Then
                b = False
                c = c + "VIP"
            End If
           
            If c = Chr$(13) Then
                c = "VIP" + c
                b = True
            End If
         
            try = try + c
        Next
        Me.RichTextBox1.SelText = try
    End If

End Sub

Avatar of vip110598

ASKER


Thanks alot,
however,

Could you write it so that it just writes VIP at the begining of the line?

I will use that answer with your first one.
Not both at the same time...

yes ,

in the comment instead of


            If c = Chr$(13) Then
                c = "VIP" + c
                b = True
            End If

put :

            If c = Chr$(13) Then
                b = True
            End If

Thank you. :)