Results 1 to 4 of 4

Thread: Formatting in a webpage

  1. #1

    Thread Starter
    Lively Member k7l2010's Avatar
    Join Date
    Feb 2017
    Posts
    70

    Formatting in a webpage

    Hi
    Please help, how does this code work? It needs fixing, please help

    Web.Document.getElementById("T6").Value.replace(/\n\r?/g,"<br />")

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

    Re: Formatting in a webpage

    i would think that in VB6 you would a) have to replace each of the characters separately, b) that each would have to be enclosed in quotes and c) the correct format would be like
    Web.Document.getElementById("T6").Value = replace(Web.Document.getElementById("T6").Value,"\n","<br />")

    using regular expressions may provide some alternatives
    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

  3. #3
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    764

    Re: Formatting in a webpage

    Quote Originally Posted by k7l2010 View Post
    Web.Document.getElementById("T6").Value.replace(/\n\r?/g,"<br />")
    This code replaces any occurrence of a line feed character ("\n" = CHR(10)) optionally followed by a carriage return character ("\r" = CHR(13)) with an HTML Break entity ("<br/>"), which is how you do line breaks in HTML.

    Not sure which platform this is intended for, though. Windows uses "\r\n" for its line breaks, Unix uses just "\n" and, IIRC, Apple uses "\r".

    If I were coding this, I'd do something like this:

    Code:
    dim ele As Object : Set ele = Web.Document.getElementById("T6")
    ele.Value = Replace( Replace( ele.Value, Chr(13), "" ), Chr(10), "<br/>" )
    '                                        ^              ^
    '                                        |              Replace line breaks with BR entities
    '                                        Remove carriage returns completely
    Regards, Phill W.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Formatting in a webpage

    Quote Originally Posted by Phill.W View Post
    This code replaces any occurrence of a line feed character ("\n" = CHR(10)) optionally followed by a carriage return character ("\r" = CHR(13)) with an HTML Break entity ("<br/>"), which is how you do line breaks in HTML.

    Not sure which platform this is intended for, though. Windows uses "\r\n" for its line breaks, Unix uses just "\n" and, IIRC, Apple uses "\r".

    If I were coding this, I'd do something like this:

    Code:
    dim ele As Object : Set ele = Web.Document.getElementById("T6")
    ele.Value = Replace( Replace( ele.Value, Chr(13), "" ), Chr(10), "<br/>" )
    '                                        ^              ^
    '                                        |              Replace line breaks with BR entities
    '                                        Remove carriage returns completely
    Regards, Phill W.
    Unless you want to be semantically correct about it, carriage returns solo should be break tags, while line feeds should be paragraph tags. But, as you pointed, out, it also depends on what the source material is. It's a potentially sticky wicket.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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