Your name or email adress:
Do you already have an account?
Forgot your password?
  • Log in or Sign up



    Advertise here
    Results 1 to 8 of 8
    1. #1
      Join Date
      Dec 2011
      Posts
      253
      MTV$
      999
      Thanks
      0
      Thanked 3 Times in 3 Posts

      ASP Tutorial Part 2 - Output And Variables

      Introduction

      In the last part I explained a little about how to write ASP and how to tell the server that you have ASP code in your file and what language it is written in. In this part I will explain what is probably the most important use of ASP: output.

    2. # ADS
      Advertise here Circuit advertisement
      Join Date
      My Birthday
      Posts
      Million and counting


       
    3. #2
      Join Date
      Dec 2011
      Posts
      253
      MTV$
      999
      Thanks
      0
      Thanked 3 Times in 3 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      Sending Output To The Browser

      It's always been a tradition of programming tutorials to begin by writing the simple 'Hello World' program, so this one won't make an exception! Sending output is done using the ASP command:

      Response.Write()

      so to write 'Hello World' to the user's browser the complete code would be:

      <%@ Language=VBScript %>
      <%
      Response.Write("Hello World")
      %>

      Again, this code begins by telling the system that you are writing in VBScript. Then comes the Response.Write command. Basically this is made up of two parts. 'Response' tells the server that you want to send information to the user. There are other types of command including: Request (which gets information from the user), Session (for user session details), Server (for controlling the server) and Application (for commands relating to the application). More about these later.

      The second part, 'Write', tells the server that the type of response you would like to send is to write information to the user's browser. This doesn't just have to be text, but can include variables, which will be discussed in more depth later in this tutorial.

    4. #3
      Join Date
      Dec 2011
      Posts
      253
      MTV$
      999
      Thanks
      0
      Thanked 3 Times in 3 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      Variables

      Probably the most important feature of a programming language is a variable. A variable is basically a way of storing text, numbers or other data, so that it can be referenced later. For example, to change the earlier 'Hello World' script:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      Response.Write(OutputText)
      %>

      The output of this code will be exactly the same as the first script, but it is fundementally different as it uses variables. Basically what this code does follows:

      OutputText = "Hello World"

      This line sets up a variable called OutputText and stores in it the string of letters 'Hello World'. As this is now stored in a variable, you can now reference this text you have stored in any part of your script, and you can also manipulate it. The next line:

      Response.Write(OutputText)

      tells the server that you are sending information to the browser, and that the information to be sent is the contents of the variable called OutputText. Please note that the variable name is not enclosed in quotation marks. If you did this the browser would simply output the title of the variable as text.

      There is a second way of outputting the values of variables, other than using Response.Write. The earlier code could have been written:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      =OutputText
      %>

      In this example, the = sign is used instead of ResponseWrite.

    5. #4
      Join Date
      Dec 2011
      Posts
      253
      MTV$
      999
      Thanks
      0
      Thanked 3 Times in 3 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      Variable Operations

      The main benefits to storing information in variables is that you can use the text over and over again. For example, once storing "Hello World" in the variable OutputText, I can then use it in various places in my code:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      %>

      This is my <% =OutputText %> script. The whole reason for it is to output the text <% =OutputText %> to the browser.

      which would display in the browser:

      This is my Hello World script. The whole reason for it is to output the text Hello World to the browser.


      You can also do various operations on text stored in variables using len, left and right.

      The len function simply tells you how many characters are in a string, so if you used the following code:

      <% =len(OutputText) %>

      The server would return to the browser the
      length of the text stored in OutputText, in this case "Hello World", so the browser would display the number 11 on the screen. You could also assign this value to a variable using:

      <% StringLength = len(OutputText) %>

      which would set the value of the variable called StringLength to 11.

      You can also use the functions left and right. These will display only part of the variable. For example:

      <% =left(OutputText, 2) %>

      which would display:

      He

      and the code:

      <% =right(OutputText, 4) %>

      would display:

      orld

      Basically, these functions take the number of characters specififed from the left or right of the string, so left("Some Text", 5) takes the first 5 characters of the text.

    6. #5
      Join Date
      Sep 2012
      Posts
      1,124
      MTV$
      3,336
      Thanks
      1
      Thanked 3 Times in 3 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      this code begins by telling the system that you are writing in VBScript. Then comes the Response.Write command. Basically this is made up of two parts. 'Response' tells the server that you want to send information to the user. There are other types of command including: Request (which gets information from the user), Session (for user session details), Server (for controlling the server) and Application (for commands relating to the application). More about these later.

    7. #6
      Join Date
      Sep 2012
      Posts
      1,037
      MTV$
      1,042
      Thanks
      2
      Thanked 2 Times in 2 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      Variables

      Probably the most important feature of a programming language is a variable. A variable is basically a way of storing text, numbers or other data, so that it can be referenced later. For example, to change the earlier 'Hello World' script:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      Response.Write(OutputText)
      %>

      The output of this code will be exactly the same as the first script, but it is fundementally different as it uses variables. Basically what this code does follows:

      OutputText = "Hello World"

      This line sets up a variable called OutputText and stores in it the string of letters 'Hello World'. As this is now stored in a variable, you can now reference this text you have stored in any part of your script, and you can also manipulate it. The next line:

      Response.Write(OutputText)

      tells the server that you are sending information to the browser, and that the information to be sent is the contents of the variable called OutputText. Please note that the variable name is not enclosed in quotation marks. If you did this the browser would simply output the title of the variable as text.

      There is a second way of outputting the values of variables, other than using Response.Write. The earlier code could have been written:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      =OutputText
      %>

      In this example, the = sign is used instead of ResponseWrite.

    8. #7
      Join Date
      Jun 2013
      Posts
      769
      MTV$
      1,993
      Thanks
      0
      Thanked 1 Time in 1 Post

      Re: ASP Tutorial Part 2 - Output And Variables

      Output And Variables is one of the part of the value that is used to be one of the displaying the contents of the variable in the HTML by using the ASP and so many other output things. they are used to allow one of the Response.Write method to place the contents of asp and so on.

    9. #8
      Join Date
      Mar 2014
      Posts
      752
      MTV$
      1,987
      Thanks
      0
      Thanked 9 Times in 6 Posts

      Re: ASP Tutorial Part 2 - Output And Variables

      Variables

      Probably the most important feature of a programming language is a variable. A variable is basically a way of storing text, numbers or other data, so that it can be referenced later. For example, to change the earlier 'Hello World' script:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      Response.Write(OutputText)
      %>

      The output of this code will be exactly the same as the first script, but it is fundementally different as it uses variables. Basically what this code does follows:

      OutputText = "Hello World"

      This line sets up a variable called OutputText and stores in it the string of letters 'Hello World'. As this is now stored in a variable, you can now reference this text you have stored in any part of your script, and you can also manipulate it. The next line:

      Response.Write(OutputText)

      tells the server that you are sending information to the browser, and that the information to be sent is the contents of the variable called OutputText. Please note that the variable name is not enclosed in quotation marks. If you did this the browser would simply output the title of the variable as text.

      There is a second way of outputting the values of variables, other than using Response.Write. The earlier code could have been written:

      <%@ Language=VBScript %>
      <%
      OutputText = "Hello World"
      =OutputText
      %>

      In this example, the = sign is used instead of ResponseWrite.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

    Tags for this Thread

    Bookmarks

    Posting Permissions

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