#1
  1. Web Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Finland
    Posts
    719
    Rep Power
    15

    Multiple lines with one command


    Hi all

    I gotta ask this, since I'm in a dispute with my ASP teacher. We are writing small ASP scripts, you know trying to learn it but the way we write ASP is pretty complicated for me. Here is a simple example of our scritps:
    Code:
    <%
    Language = VBScript
    Dim strEtunimi
    
    Response.Expires = 0
    If Request.ServerVariables("QUERY_STRING") <> "" Then
      strEtunimi = Request.QueryString("etunimi")
      response.write "Your name is <b>" & strEtunimi & "</b>"
    %>
    <% Else %>
    <html>
    <body>
    
    Personal data:
    <form name="formis" method="get" action="vastaus_v2.asp">
    Etunimi:&nbsp;&nbsp; <input type="text" name="etunimi" value="">
    <p>
    <input type="submit" value="Lähetä">&nbsp;&nbsp;
    <input type="reset" value="Tyhjennä">
    </form>
    
    </body>
    </html>
    <% End If %>
    What bothers me is the multiple opening and closing ASP tags on the document. With PHP I've got used to the idea that I can put everything inside one set of PHP tags. In this example both the Else and the End If are enclosed in their own ASP tags and that freaks me out (I like details). I can only imagine how this looks if we would be writing a much more complex and bigger application.

    What I'd like is to enclose all of this inside one set of ASP tags and have Response.Write print all the necessery HTML code. Is this possible?
    -- Tomi Kaistila
    -- Developer's Journal

    The more you learn, the more you know.
    The more you know, the more you forget.
    The more you forget, the less you know.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    NJ
    Posts
    428
    Rep Power
    16
    Of course you can put your whole page in respnse.write tags if you wish. But believe it or not Interleaved code is faster than all response.write statements. (See this article: http://www.4guysfromrolla.com/webtech/021302-1.shtml) I think PHP lends itself a little bit better to limiting the code to one set of <? ?> tags. Since your strings can wrap multiple lines as long as you end it with a ; when you are done. And the ability to write variables without having to concatentate strings. stuff like that. Plus, echo is much easier to write then response.write. I had half a mind to write a sub in asp:

    PHP Code:
    sub echo (str)
      
    response.write str
    end sub 
    but i thought that would piss off anyone else that needed to modify my code in the future.
  4. #3
  5. No Profile Picture
    Overly white
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Fresno, CA
    Posts
    83
    Rep Power
    12
    Sure you could have response.write print out all of your html, but I think that may be more difficult to read and trouble shoot HTML issues. But you could do something like this. The only issue is that when you have something in double quotes you need to either use 3 quotes (I think), or use single quotes. This is why I just try to avoid that issue and just just have multipul <% %> tags.

    Code:
    <%
    Language = VBScript
    Dim strEtunimi
    
    Response.Expires = 0
    If Request.ServerVariables("QUERY_STRING") <> "" Then
      strEtunimi = Request.QueryString("etunimi")
      response.write "Your name is <b>" & strEtunimi & "</b>"
    Else
      response.write "<html>"
      response.write "<body>"
    
      response.write "Personal data:"
      response.write "<form name='formis' method='get' action='vastaus_v2.asp'>"
      response.write "Etunimi:   <input type="""text""" name="""etunimi""" value=""">"
      response.write "<p>"
    ...
      response.write "</body>"
      response.write "</html>"
    End If
    %>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    NJ
    Posts
    428
    Rep Power
    16
    when i do use long response.write statements then you can always use the underscore to continute lines:

    PHP Code:
    response.write "<html>" _
                           
    "<head>" 
                          
    "<title>HI there</title>" 
                           
    "</head>" 
    of course that will show in html as

    <html><head><title>HI there</title></head>

    unless of course you do this.

    PHP Code:
    response.write "<html>" vbcrlf _
                           
    "<head>" vbcrlf 
                          
    "<title>HI there</title>" vbcrlf 
                           
    "</head>" 
    I'll also do my sql statements like this for readablity:

    PHP Code:
    sql "select * " _
            
    "from table1 " 
            
    "where ID=1" 
  8. #5
  9. Web Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2001
    Location
    Finland
    Posts
    719
    Rep Power
    15
    Thank you for such speady replies. They were really helpful. Rewritten code of the example script would look something like this:
    Code:
    <%
    Language = VBScript
    Dim strEtunimi
    
    Response.Expires = 0
    If Request.ServerVariables("QUERY_STRING") <> "" Then
      strEtunimi = Request.QueryString("etunimi")
      response.write "Etunimesi on <b>" & strEtunimi & "</b>"
    Else
      response.write "<html>" & _
    "<body>" & vbcrlf & _
    "Henkilötietojen syöttäminen:" & vbcrlf & _
    "<form name='formis' method='get' action='vastaus_v2.asp'>" & vbcrlf & _
    "Etunimi:&nbsp;&nbsp; <input type='text' name='etunimi' value=''>" & vbcrlf & _
    "<p>" & vbcrlf & _
    "<input type='submit' value='Lähetä'>&nbsp;&nbsp;" & vbcrlf & _
    "<input type='reset' value='Tyhjennä'>" & vbcrlf & _
    "</form>" & vbcrlf & _
    "</body>" & vbcrlf & _
    "</html>"
    End If
    %>
    Much more compact in my opinion and more simple to write more complicated applications, though a little clumsy with all the quotes and underscores but I got what I wanted

    Thanks again for the advices.
    -- Tomi Kaistila
    -- Developer's Journal

    The more you learn, the more you know.
    The more you know, the more you forget.
    The more you forget, the less you know.

IMN logo majestic logo threadwatch logo seochat tools logo