Results 1 to 3 of 3

Thread: Replace with multiple lines

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Replace with multiple lines

    I want to replace multiple lines with whatever is entered into a textbox.
    Code:

    Text1 = Replace(Text1, "<div id=""bodytext_wide"">" & vbCrLf & _
    "" & vbCrLf & _
    "<p>CODEHERE</p>" & vbCrLf & _
    "<p>CODEHERE</p>" & vbCrLf & _
    "<p>CODEHERE</p>" & vbCrLf & _
    "<p>CODEHERE</p>" & vbCrLf & _
    "<p>CODEHERE</p>" & vbCrLf & _
    "<p>" & vbCrLf & _
    "</div> ", Text4)

    but it doesnt replace....

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Replace with multiple lines

    Multiple lines of what?! And seriously, you can ask these subquestions in a same thread.

    First of all, "doesn't work" tells us absolutely nothing about your problem, and we are then unable to help you. You need to describe what the exact problem is, if you get an error copy the error message, if the code behaves differently than what you expected you need to clearly state what you wanted it to do and what id does currently.

    Replace function works by looking for a substring of another string, and replaces it with the third string. Mind that this operation is case sensitive, meaning "Code" is not the same as "code". If calling it doesn't replace, then it means it did not find the string it was looking for.

    Some more off topic tips:

    1. avoid relying on default properties. Instead of using Text1 = ... write Text1.Text =
    2. When posting code in this forum enclose it in code tags ([code] [ /code]) so it's easier to read.
    3. Adopt a naming convention for objects/controls and variables. It will make your life a lot easier later on when your projects get bigger. When naming a Textbox use txt prefix, so it will be txtName, cmdButton, lblSomeLabel etc. For variables do intNumber for Integer, strData for String etc etc. That way you know what something is just by looking at it, and wont have to hunt down declarations to find out what something is. EDIT: Here's an article on this http://support.microsoft.com/kb/110264

    EDIT2: Just looked at your code again, this is not a string: "<p>CODEHERE</p>" & vbCrLf & _ ... thats a piece of code because of the underscore. You are breaking lines of code, not breaking lines in the string. _ needs to be in quotes to be considered a string.

    EDIT3: As your project involves a lot of string manipulation, it will do you a world of good to read a tutorial or two on the subject so you understand what functions and tools are available to you so you can better solve a particular problem. Here is a good one http://www.vb6.us/tutorials/vb6-string-functions
    Last edited by baja_yu; Sep 12th, 2010 at 08:59 PM.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Replace with multiple lines

    if the exact string does not match a partial content of text1, including matching of case, even to the space after </div>
    nothing will be replaced
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width