Solved

Replace Text in a TextBox

Posted on 2004-08-25
10
189 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
  • 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
 
LVL 2

Author Comment

by:gerrymcd
ID: 11893059
Your back, lol.  thanks thats perfect again.  Cant believe i missed that.  something so simple.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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

760 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

19 Experts available now in Live!

Get 1:1 Help Now