Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Replace Text in a TextBox

Posted on 2004-08-25
10
Medium Priority
?
197 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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

609 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