Solved

Replace Text in a TextBox

Posted on 2004-08-25
10
195 Views
Last Modified: 2006-11-17
How i replace text a line number in a textbox.  Without using the VB replace function as there will be more that one test line in the text box the same?

Can a richtextbox do it?

Example

So hold on  <how do i replace this line only to say "[00:30] So hold on"
So come on
So hold on
So come on
0
Comment
Question by:gerrymcd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11892914
replace has additional optional parameters:

Replace(expression, find, replacewith[, start[, count[, compare]]])

expression  - Required.String expression containing substring to replace.
find            - Required. Substring being searched for.
replacewith - Required. Replacement substring.
start           - Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
count          - Optional. Number of substring substitutions to perform. If omitted, the default value is &#8211;1, which means make all possible substitutions.
compare     - Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.

Try to use start and count parameters according to your needs.

HTH
0
 
LVL 2

Author Comment

by:gerrymcd
ID: 11892952
could you give an example on the 4 lines i posted?
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11892961
To replace just first line from you example you should try sthg like this
Text1.Textr = Repalce(Text1.Text, "So hold on", "[00:30] So hold on",1,1)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 2

Author Comment

by:gerrymcd
ID: 11893059
Your back, lol.  thanks thats perfect again.  Cant believe i missed that.  something so simple.
0
 
LVL 2

Author Comment

by:gerrymcd
ID: 11893160
er it didnt work

So hold on  
So come on
So hold on
So come on

text1=Replace(Text1.Text, s, "[00:30]" & s, 3, 1)

result;

o hold on  
So come on
[00:30]So hold on
So come on

Can you help?


0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11893193
text1=Replace(Text1.Text, s, "[00:30]" & s, 1, 1)

Your code started search from third character, not from begining of string
0
 
LVL 2

Author Comment

by:gerrymcd
ID: 11893235
so how do i add "[00:30]" to the third line then?
0
 
LVL 8

Accepted Solution

by:
mladenovicz earned 75 total points
ID: 11893421
Dim CurrPos As Long
Dim s As String


    CurrPos = 1
    s = "So hold on"
    Text1.Text = Replace(Text1.Text, s, "[0:30]" & s, CurrPos, 1)
    CurrPos = CurrPos + LineLength(Text1, 0)
    s = "So come on"
    If InStr(CurrPos, Text1.Text, s) > 0 Then
        Text1.Text = Left(Text1.Text, CurrPos) & Replace(Text1.Text, s, "[1:00]" & s, CurrPos, 1)
    End If
    CurrPos = CurrPos + LineLength(Text1, 1)
    s = "So hold on"
    If InStr(CurrPos, Text1.Text, s) > 0 Then
        Text1.Text = Left(Text1.Text, CurrPos) & Replace(Text1.Text, s, "[1:30]" & s, CurrPos, 1)
    End If
    CurrPos = CurrPos + LineLength(Text1, 2)
    s = "So come on"
    If InStr(CurrPos, Text1.Text, s) > 0 Then
        Text1.Text = Left(Text1.Text, CurrPos) & Replace(Text1.Text, s, "[2:00]" & s, CurrPos, 1)
    End If
0
 
LVL 2

Author Comment

by:gerrymcd
ID: 11893620
Thanks.  
In the end i used an Array to refresh the text box.
0

Featured Post

Industry Leaders: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

696 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