Got 10 minutes? Want to get started with ASP Classic?
This article is part of our series of 10 Minute Quick Starts. Each quick start is step by step, assumes you know very little about the subject, and takes about 10 minutes. You can use them to scratch the service of areas you want to learn and as a quick review when returning to something after a long absence.
ASP Classic
In the details below are complete and simple examples of using ASP within your code directly, calling a subroutine, and calling a function.
Part 1. Simple ASP Example
Create first script. Here is a complete example inside an HTML page. As long as your on IIS and the file has an .asp extension, the code will execute. Create this file with any editor, including Notepad, and save as helloworld.asp.
Notice how the ASP code is included between opening <% and closing %>. In this case, the first two lines and within the the body tags.
@language="vbscript" - This first line tells the server that VBScript is in use. It's a bit redundant for ASP pages but I like to include it just in case the default language on the server ever changes (for example to JScript).
Option Explicit - Declaring variables is optional unless you use the Option Explicit statement to force explicit declaration of all variables with Dim in that script. Using Option Explicit is strongly recommended to avoid incorrectly typing an existing variable and to avoid any confusion about variable scope.
Copy it. Copy the file to your website.
Runt it. Then browse to the page (something like http://www.yourserver.com/helloworld.asp).
Part 2. Simple Subroutine and Function Samples
ASP also has subroutines and functions. You can place the subroutines anywhere, but typically ASP programers place them in the header or below the final html tag. Here's an example of using a subroutine in the header that is called from your html.
'DisplayMsg1 ' A single quote marks a comment line in ASP.
'''''''''''''''''''''''''''''''''''''''''''''
Sub DisplayMsg1
Response.Write "Hello World!"
End Sub
DisplayMsg1
ASP also gives you functions. A function is just like a subroutine except it returns a value. In this example of using a function, we chose to put the function below the final html tag. Some programmers prefer this approach because it allows you to isolate all your subroutines and functions "after" your mixture of html/asp calls. The ASP.DLL first loads your entire page (and all includes) and then runs the script. Because of this two pass approach, it doesn't matter "where" you put subroutines, functions, constants, and variables. (We'll talk more about the "scope" of constants and variables later.)
This example also introduces the "=" operator, declaring and setting a variable, and a function. The "=" operator is used both to set a variable and to send output to html.
DisplayMsg2 Function DisplayMsg2
Dim StrTemp 'Declare variable as a variant
'(ASP does not offer variable types).
StrTemp = "Hello World" 'Assign string to variable.
DisplayMsg = StrTemp 'Return string.
End Function
The following is a complete example using a sub and function. Notice you can define subs and functions anywhere. For demonstration one function is declared at the top and one at the bottom. You'll have to decide what style you like best. My preference is to locate all subs and functions at the bottom of the script file.
<%@LANGUAGE='VbScript'%> <% Option Explicit
Sub DisplayMsg1 Response.Write "ASP is easy.<br>" End Sub %>
<html>
<body>
<% Dim FullName 'de clare a variable.
FullName = "Mike Prestwood"
Response.Write "I am an ASP classic coder!<br>" DisplayMsg1 %>
<p>The following uses = to easily show ASP returned values in HTML.</p>
<p>Hi <%=FullName%></p>
<p><%=DisplayMsg2%></p>
</body>
</html>
<% Function DisplayMsg2 Dim StrTemp 'de clare variable as a variant '(ASP does not offer variable types).
StrTemp = "Coding in ASP is fun!!!" 'Assign string to variable.
DisplayMsg2 = StrTemp 'Return string. End Function
Simple ASP coding is much easy than an advanced one because a lot of working in this field and they suggest work on it. The best essay writing service shares a lot of courses which you can watch if you are a newbie in the field.
hi there, I such as playing casino site video games. do you like it also? if your response is yes, go and inspect my Shadow Bet Casino Review. There you ‘ll locate the best conditions, you ‘ll have an opportunity to deposit as well as withdrawal at any time you want. best of luck!
Yesterday I asked the managers on this site, "Can you do my assignment for me online?" I was surprised at the quality of the paperwork and the deadline.