| ~Wildfire: > Articles > Starting ASP Programming (February 13th 2000) | |
| ~Look at: | Articles | FAQs | Resources | Reference | | |
|
This article follows on from the article An Introduction to Active Server Pages. This article will introduce the basics of Server-Side scripting using VBScript. Some familiarity with the VB language is helpful, but the examples should be explained sufficiently for use by those who have no previous programming experience. Contents
The Basic Structure of an ASPAn ASP can be broken down into two main sections:
The code that is executed on the server is VBScript (for this tutorial) and the code that is sent to the client is standard HTML. The ASP processes the server-side code and then based on decisions that the code makes selects code to send to the client. This means that pages can be customised for the user at the server, sending a simple HTML page to the user. Starting an ASPThere is only one bit of code that is essential to include in every ASP. This is the code that tells the server what language the page is programmed in:
<%@ LANGUAGE="VBSCRIPT" %>
This is all that is needed. The rest of the page can now be filled with HTML code to send to the client with VBScript code to perform calculations and actions. The tags that the Active Server Script resides within are the "<%" and "%>" tags. Anything between these tags (apart from VBScript comments) is parsed and acted upon by the server. How to Comment Your CodeAll developers want to comment their code at some point so that they can remember the particulars of the way their applications work. This is very easy to do. All you need is an apostrophe " ' " before any text that you want ignored:
<% ' this is a comment%>
Hello WorldAs with any new language the first tutorial will demonstrate how to do a "Hello World" type function, not to break with tradition here is a small example of how to write several "Hello World"s to the client: <%@
LANGUAGE="VBSCRIPT"%> Go through the above script to make sure that you understand it. The first section of code makes the variable "theMessage" store the value "Hello World". It then uses an ASP method "response.write" to write out the contents of "theMessage" and an HTML line break to the client. A simple HTML paragraph is then included. The next snippet of ASP code, note the equals sign (=) simply writes out the contents of "theMessage" to the client. You have now learnt two ways of writing custom data to the client, now to take it to a slightly more advanced level: A Simple VB Script PageTo start off your VBScript/ASP programming here is a sample piece of code that will loop through various heading sizes: <%@
LANGUAGE="VBSCRIPT" %> This will generate a custom HTML page to be sent to the client. The HTML that the client's browser will recieve will be: <HTML> This code will be rendered on the screen without the client ever knowing what processing there was on the server. What the ASP code does is take the variable "times" and set it to be "1" it then writes out the heading code inserting the variable (a number) in the places where the number appears in the HTML code: in the <HX> tags and in the text. The code then loops, at the point "next", incrementing the variable "times" by one and looping through the code until "times" is "3". It then just sends out the rest of the page as normal. In SummaryIn this article you have learnt how to code a basic ASP page. Hopefully you will understand the VBScript, even if you are unfamiliar with general programming altogether. If you have any basic ASP questions don't hesitate to email me, if I can't answer the question myself then I'll point you in the right direction. ASP Tutorial: Next Article - Using Forms and Querystrings in ASPs; Previous Article - An Introduction to Active Server Pages Microsoft have released a new version of ASP: ASP+, more information from the Microsoft.net site
|
|||
| Top of Page | |
| ~Look at: | Articles | FAQs | Resources | Reference | | |
| © Jamie McHale 1998 - 2000 - http://www.btinternet.com/~wildfire/ |