Results 1 to 11 of 11

Thread: [RESOLVED]Add & VbCrLf & _ to the end of every line?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Resolved [RESOLVED]Add & VbCrLf & _ to the end of every line?

    Im building a program that helps with php code. It has a ton of lines, so i need to add & VbCrLf & _ to the end of every line. Can i make a program that does this for me?
    Last edited by timbowman1; Sep 12th, 2010 at 08:44 PM.

  2. #2
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Add & VbCrLf & _ to the end of every line?

    Yup, you can!

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Add & VbCrLf & _ to the end of every line?

    =o

    Stop messin with me, man!
    May you teach me how?

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

    Re: Add & VbCrLf & _ to the end of every line?

    Each end of line is a VbCrLf character (a line break), so you can use Replace function to do something like this

    strData = Replace(strData, vbCrLf, vbCrLf & " & VbCrLf & _")

    if I understood correctly, that you wanted to append that as string, if not just change it to match what you want.

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Add & VbCrLf & _ to the end of every line?

    Now, most of the lines have & VbCrLf & _ in front of them.
    However, only the first line has black text and all the other lines have red text (error). It also added a " to the first line.

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

    Re: Add & VbCrLf & _ to the end of every line?

    possibly the easiest way is to split into an array then you can manipulate each element of the array as required

    the text in each line must be enclosed in quotes

    i believe the above example should have a space between the last & and the _ which is hidden by the html rendering of the page
    Code:
    strData = Replace(strData, vbCrLf, " _" & vbCrLf & " & VbCrLf &  ")
    or if more suitable
    Code:
    strData = Replace(strData, vbCrLf, " & VbCrLf &  _ " &  vbCrLf )
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Add & VbCrLf & _ to the end of every line?

    I still get errors. Can you try your code with this example code?
    <?php
    if (!isset($page_title)) $page_title=""PHP code and online MySQL database - example username password"";
    if (!isset($page_keywords)) $page_keywords=""free PHP code, mysql sql"";
    if (!isset($page_desc)) $page_desc=""FREE example PHP code and a MySQL database"";
    ?>
    <html>

    <head>
    <title><?php echo $page_title; ?></title>
    <meta NAME=""keywords"" CONTENT=""<?php echo $page_keywords; ?>"">
    <meta NAME=""description"" CONTENT=""<?php echo $page_desc; ?>"">
    <meta NAME=""Content-Language"" CONTENT=""english"">
    <meta name=""Revisit-after"" content=""56 days"">
    <meta name=""Distribution"" content=""Global"">
    <meta name=""Copyright"" content=""Copyright © 1996-2008 Seiretto.com"">
    <meta NAME=""ROBOTS"" CONTENT=""ALL"">
    <link rel=""stylesheet"" type=""text/css"" href=""tds.css"">
    </head>

    <body BACKGROUND=""DiscoverBack.gif""
    style=""
    SCROLLBAR-ARROW-COLOR: #BBCCFF;
    SCROLLBAR-TRACK-COLOR: #C9DAF7;
    SCROLLBAR-FACE-COLOR: #002163;""
    TOPMARGIN=""0"" LEFTMARGIN=""15"" MARGINWIDTH=""0"" MARGINHEIGHT=""0"">
    <div align=""center""><center>

    <table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0"">
    <tr>
    <td width=""100%""><p align=""center""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""></td>
    </tr>
    <tr>
    <td width=""100%""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""><div align=""center""><center><table
    border=""0"" width=""98%"" cellspacing=""0"" cellpadding=""0"">
    <tr>
    <td width=""9%""><font face=""Comic Sans MS""><strong><big>&nbsp;PHP.TheDemoSite.co.uk</big></strong></font></td>
    <td><p align=""center""><small>Just examples of <b>PHP</b> code, linking to your <b>MySQL</b>
    database and JavaScript.<br>
    <a href=""index.php"">1. Home</a> | <a href=""thedatabase.php"">2. The Database</a> | <a
    href=""addauser.php"">3. Add a User</a> | <a href=""login.php"">4. Login</a> | <a
    href=""getyourowndbonline.php"">5. Get your db online</a></small></td>
    </tr>
    </table>
    </center></div></td>
    </tr>
    <tr>
    <td width=""100%""><p align=""center""><img height=""2"" src=""line.gif"" width=""99%"" border=""0""
    alt=""PHP code examples with database connectivity""><br>
    </td>
    </tr>
    </table>
    </center></div>
    <p align=""center""><i>Also, while here don't forget to have a look at <a href=""http://thedemosite.co.uk/phpformmailer/""><strong>phpFormMailer </strong>(easy to use PHP form mail - more secure than many cgi form mail</a>) </i></p>
    <? include(""hostscripts-12870.inc"");?>
    </table>

    <table border=""0"" width=""100%"">
    <tr>
    <td>"

  8. #8

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Add & VbCrLf & _ to the end of every line?

    When i use

    I get
    helo" & vbCrLf & _this" & vbCrLf & _is" & vbCrLf & _a" & vbCrLf & _test" & vbCrLf & _
    instead of
    helo" & vbCrLf & _
    this" & vbCrLf & _
    is" & vbCrLf & _

    etc

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2010
    Posts
    14

    Re: Add & VbCrLf & _ to the end of every line?

    GAH.. i did it manually... 197 lines of code.

  10. #10
    Hyperactive Member Max Peck's Avatar
    Join Date
    Oct 2007
    Posts
    384

    Re: Add & VbCrLf & _ to the end of every line?

    Quote Originally Posted by timbowman1 View Post
    =o

    Stop messin with me, man!
    May you teach me how?
    Sorry about that bud. Sometimes we get posters (usually with a low post count) that come in here with generalized questions like that having done nothing asking the group to do the work for them. Looks like you've gotten some assistance though ... so rock on!

    -Max
    The name's "Peck" .... "Max Peck"

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

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

    Re: [RESOLVED]Add & VbCrLf & _ to the end of every line?

    GAH.. i did it manually... 197 lines of code.
    for your future reference
    while it is easy to do what you wanted, you can not do it within the same project (or at least not easily)

    the simple method is to start a new project with the following code, either in a commandbutton or sub main (no form required)

    vb Code:
    1. strdata = clipboard.gettext
    2. strData = Replace(strData, vbCrLf, """ & VbCrLf &  _ " & vbCrLf & """")
    3. clipboard.clear
    4. clipboard.settext strdata

    copy all the php code to clipboard, run the project, paste from clipboard to main project
    note: there is a limitation on how many line continuations you can have, so you may get an error message "too many line continuations"

    you can also open vb .frm files as text files, from vb, and edit the contents by code, but again you must follow vb's rules, you will get no error on writing the files, but may when reopening the file within the vb project
    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