?
Solved

Replace Text in a TextBox

Posted on 2004-08-25
10
Medium Priority
?
196 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
Technology Partners: 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!

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

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

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 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