Solved

Replace Text in a TextBox

Posted on 2004-08-25
10
190 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
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.

 
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

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
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…

895 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

17 Experts available now in Live!

Get 1:1 Help Now