Results 1 to 13 of 13

Thread: Simple question

  1. #1

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Question Simple question

    hi all,

    Need something pretty urgently....

    how can i dump a small html code in a variable ? do i need to take array ?

    i need to write below line to a file "as is"

    Code:
    $a = "<style>"
    $a = $a + "BODY{background-color:skyblue;}"
    $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
    $a = $a + "</style>"
    how can i make VB turn off recognition of it's operative characters like $,<,>,= etc. which appears on above code but i need to dump it "as it is" in a file during runtime.

    pls help...

  2. #2
    Member
    Join Date
    Dec 2005
    Location
    Philadelphia
    Posts
    48

    Re: Simple question

    Code:
            Dim a As String = "<style>"
            a += "BODY{background-color:skyblue;}"
            a += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
            a += "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
            a += "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
            a += "</style>"

  3. #3

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Question Re: Simple question

    Quote Originally Posted by Royal View Post
    Code:
            Dim a As String = "<style>"
            a += "BODY{background-color:skyblue;}"
            a += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
            a += "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
            a += "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
            a += "</style>"
    appreciate the reply but that's not precisely what i want...

    for eg. i initialized a string StrData then i want StrData to store the entire code written in my first post & then finally dump that into a text file
    for eg :

    Code:
    Dim StrData as String
    StrData = "$a = "<style>""
    StrData += "$a = $a + "BODY{background-color:skyblue;}""
    ....
    ....
    so what i want is that string should save $ , = etc as a "string" data & NOT as a operator

  4. #4

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Re: Simple question

    guys pls...there shud be something to resolve this ....

  5. #5
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Simple question

    Technically, if it is wrapped in quotation marks, it will be taken literally. What's wrong with the example code you put, excluding the fact that you've forgotten to add Environment.NewLine() behind each of your lines.

  6. #6

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Question Re: Simple question

    Quote Originally Posted by MaximilianMayrhofer View Post
    Technically, if it is wrapped in quotation marks, it will be taken literally. What's wrong with the example code you put, excluding the fact that you've forgotten to add Environment.NewLine() behind each of your lines.
    vb does not take my code as is , it gives me syntax error & stuff ahead of either "=" or "$" or "< , >"

  7. #7
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Simple question

    If you have a literal " in your string, you have to escape it with another ". Simple as that.
    So let's say you have this string
    Code:
    $a = $a + "BODY{background-color:skyblue;}"
    And you want to assign it to a string variable, you have to enclose that string in " to tell the compiler that this is a string, and then you escape any literal " that you have in that string. So the code will look like this:
    Code:
    Dim myString As String = "$a = $a + ""BODY{background-color:skyblue;}"""
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Simple question

    This works for me:

    Code:
    Dim a As String = "<style>" & System.Environment.NewLine
            a &= "BODY{background-color:skyblue;}" & System.Environment.NewLine
            a &= "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & System.Environment.NewLine
            a &= "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & System.Environment.NewLine
            a &= "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & System.Environment.NewLine
            a &= "</style>"
            MsgBox(a)
    To write it to a file you use a streamwriter next.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Simple question

    Quote Originally Posted by GaryMazzone View Post
    This works for me:

    Code:
    Dim a As String = "<style>" & System.Environment.NewLine
            a &= "BODY{background-color:skyblue;}" & System.Environment.NewLine
            a &= "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & System.Environment.NewLine
            a &= "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & System.Environment.NewLine
            a &= "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & System.Environment.NewLine
            a &= "</style>"
            MsgBox(a)
    To write it to a file you use a streamwriter next.
    Yes, it works (syntax wise) but you're also changing the string. For example, the " in the string "BODY{background-color:skyblue;}" are part of the data and they need to be preserved. However, you just dropped them completely.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Simple question

    Stan I don't think so. I copied the supplied code and use it. The BODY{background-color:skyblue}; is still in the string that is generated. I really have absolutely no idea what the OP is actually trying to do since the question appears to have changed in the middle of the thread.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Simple question

    Gary, I beleive the OP is trying to do some kind of php code generator from this line in post #1
    Code:
    i need to write below line to a file "as is"
    If you look at the code section in his initial post, what he wants is to assign everything in that section to a string variable so that he can write it out to a .php file. The code you provided is more like converting his php code to vb.net code.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  12. #12

    Thread Starter
    Lively Member sk8er_boi's Avatar
    Join Date
    Jun 2010
    Posts
    65

    Thumbs up Re: Simple question

    Finally !!!
    after a few trial & error was able to achieve wht i wanted here's what i did :

    Code:
    Dim TableFrmt As String = "$a= " & Chr(34) & "<style>" & Chr(34) & System.Environment.NewLine
            TableFrmt &= "$a = $a + " & Chr(34) & "BODY{background-color:skyblue;}" & Chr(34) & System.Environment.NewLine
            TableFrmt &= "$a = $a + " & Chr(34) & "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}" & Chr(34) & System.Environment.NewLine
            TableFrmt &= "$a = $a + " & Chr(34) & "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}" & Chr(34) & System.Environment.NewLine
            TableFrmt &= "$a = $a + " & Chr(34) & "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}" & Chr(34) & System.Environment.NewLine
            TableFrmt &= "$a = $a + " & Chr(34) & "</style>" & Chr(34) & System.Environment.NewLine
            TableFrmt &= System.Environment.NewLine
    chr(34) is for retaining double quotes "as is" like i said in my 1st post

    thx every1 for help

  13. #13
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Simple question

    If you follow these VB rules for string then it become very simple to do what you need:
    1. All literal strings need to be enclosed with double quotes.
    2. A literal double quote has to be escaped with another literal double quote.
    So let's do an example by taking your original data and assign it to a string variable.
    First you just declare a string variable and assign an empty string to it.
    Code:
    Dim myString as String = ""
    Now you copy the first line of the string data and paste it in between the quotes (rule #1), then add another double quote right to front of each and every double quote you see in the string except the 2 at the very ends of the string. It then becomes:
    Code:
    Dim myString as String = "$a = ""<style>"""
    Now if you want to add another line to this string, you append a newline character to it, and for readability, you may also using the VB line continuation but it's not required.
    Code:
    Dim myString as String = "$a = ""<style>""" & Environment.NewLine & _
    Start a new line with an empty string again and paste in the 2nd line, escape the quotes... Just repeat the steps until you're done with all the lines.
    Code:
    Dim myString as String = "$a = ""<style>""" & Environment.NewLine & _
                                      "$a = $a + ""BODY{background-color:skyblue;}""" & Environment.NewLine & _
                                      "a += '"TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}'"" & Environment.NewLine & _
                                      "a += '"TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}'"" & Environment.NewLine & _
                                      "$a = $a + '"TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}'"" & Environment.NewLine & _
                                      "$a = $a + '"</style>'""
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

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