Solved

Adding a custom value to selected lines

Posted on 1998-11-22
5
131 Views
Last Modified: 2010-05-03

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.
0
Comment
Question by:vip110598
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Inteqam earned 50 total points
ID: 1446117
you can use this on the command click event to add at the end


Private Sub Command1_Click()
    Dim n As Integer
    Dim c As String
    Dim sel As String
    Dim try As String
   
    try = ""

    If Me.RichTextBox1.SelLength > 0 Then
        sel = Me.RichTextBox1.SelText
        For n = 1 To Me.RichTextBox1.SelLength
            c = Mid(sel, n, 1)
           
            If c = Chr$(13) Then
                c = "VIP" + c
            End If
            try = try + c
        Next
        Me.RichTextBox1.SelText = try
    End If

End Sub

0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1446118
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

0
 

Author Comment

by:vip110598
ID: 1446119

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

0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1446120
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

0
 

Author Comment

by:vip110598
ID: 1446121
Thank you. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA: Add rows to listbox based on criteria 7 72
Vb.net 2008 2 56
Need VBS version of Excel date conversion 4 64
Recommendation vb6 to vb.net or others 14 105
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…

932 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

9 Experts available now in Live!

Get 1:1 Help Now