IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicTool Basics   Print This     
  From the October 2015 Issue of Prestwood eMag
 
ASP Classic Tool Basics:
A 10 Minute ASP Classic Quick Start
 
Posted 22 years ago on 8/21/2002
Take Away:

An example of using ASP's Response.Write and creating functions.

KB100014

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

  1. 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.

    <%@LANGUAGE='VbScript'%>
    <%Option Explicit%>

    <html>
    <body>

    <%Response.Write "Hello World"%>
    </body>
    </html>


    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.
     
  2. Copy it. Copy the file to your website.
  3. 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
%>

Comments

1 Comments.
Share a thought or comment...
First Comment
Comment 1 of 4

Thank you for sharing. I will proceed to reboot now!

the impossible quiz

Posted 58 months ago

Comment 2 of 4

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.

Posted 51 months ago

Comment 3 of 4

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!

Posted 50 months ago

Latest Comment
Comment 4 of 4

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.

Posted 45 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P157A1
Enter key:
Article Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #100014 Counter
21135
Since 4/2/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]