Classic ASP

Classic ASP is not used too often anymore, but it is still used. Some people also need help with this! So I will go over some basics and some more advanced things.

HTML - Basics

First is to understand HTML... Make sure you know how to use the head, title, and form. Only looking into this a little since it is extremely simple.

<html>

<!--  This is an HTML comment, it is ignored. -->

<head><title>This is the title of the page</title></head>

<body>

<p>This is the 'paragraph' tag, it is inside the 'body' tag. Most of your site will be contained in the 'body' tag.</p>

<form method=post>

<!-- The form tag is used to place form tags, such as text boxes, check boxes, and buttons.

In the form tag is 'method=post' this simply means any information that is submitted in the form

is hidden. Without this all your information submitted will show in the URL. -->

<input type=text name="name of box" value="This will show in the box">

<input type=submit name=submit value="Click to submit">

</form>

</body>

</html>

This will make a small webpage with a textbox and a submit button. This is all I will say about HTML. ASP has some basics too, I will go over them a little bit.

ASP - Variables & Output

<% ' This is how you start the script in a '.asp' file

' These single quotes are comments, they are ignored when the program runs

response.write("Hello World!")

' Response.write is used to output to the the script

' The last line '%>' is used to close the script

' Variables are important, first declare them, then assign them a value, then use them

' It is best to declare variables at the beginning of your script

dim name

' A variable called 'name' has been declared, we can now give the variable a value

name = "Jon"

' The variable 'name' has been assigned the value 'Jon' this means we can call the variable and get the value

response.write(name)

' This will output the value name contained, notice there are no quotes around the variable

%>

Now to move on to using ASP to get input from the HTML form, this is extremely important since this is how a user can interact with the webpage.

ASP - Working with HTML

<%

' Declare variables first

dim name

' Then using an ASP function you connect the variable to the 'input' tag in the HTML

name = request.form("textboxname")

' For this we will use a textbox called 'textboxname'

%>

<html>

<body>

<form method=post>

<input type=text name="textboxname" value="">

<!-- Below I have create another text box, when submit is pressed it will not only store the text from 'textboxname' into a variable but also, will use that variable to output it's text into 'anotherTextBox opening a script and using response.write. -->

<input type=text name"anotherTextBox" value="<% response.write(name) %>">

<input type=submit name="submit" value="Submit text!">

</form>

</body>

</html>

Sometimes just getting the users input is not enough. You want to do something with it, check it, well when it's stored in a variable you can do whatever you want to it.

ASP - If statements

<%

' Using if statements can be very simple, you can use it to test the value.

' If the test returns 'true' then your if statement will run, if the test returns 'false' it will not run

' But you can make the statement do something even if it is false, this can be done using 'else'

' inside the if statement. Always remember to end the if statement.

dim name

name = request.form("aTextBox")

if name = "Arya" then

response.write("Name is = to 'Arya' ")

else

response.write("Name is not = to 'Arya' ")

end if

%>

<html>

<body>

<form method=post>

<p>Please enter name:</p><input type=text name="aTextBox" value="<% response.write(name)%>">

<input type=submit name=submit value="Is your name Arya?">

</form>

</body>

</html>

If statements can be used to validate almost anything. Another useful tool is the loop, they can be used to run code multiple times. You can also use if statements inside these loops.

Lets say you wanted someone to enter a email, but you want a valid email, not just some garbage. This will also use some functions. Functions are like small programs that you can use to perform unique operations. Response.write("Hello World!") is an example of a function.

ASP - Loops & More if statements

<%

dim email

email = request.form("emailTextBox")

' What does this first line do? 'do while' starts the loop. 'instr(email, " ")' is a function with some stuff inside, what it does is

' looks through the variable email. It is looking for " " a blank space. The value is based on the value inside the variable email.

' If the " " is found inside 'email', instr will produce a number greater than '1', which is the position that it found the space.

' If it cannot find a space, it will return a '0'. Next '<>' means not equal. So '<> 0' means not equal to zero...

' The loop is read as: "do while a blank space is not found".

do while instr(email, " ") <> 0

' This next line is very simple, replace the blank space in the variable email with no space.

email = replace(email, " ", "")

' This next line ends 'do while' loops

loop

%>

<html>

<body>

<form method=post>

<p>Please enter email:</p><input type=text name="emailTextBox" value="<% response.write(name)%>">

<input type=submit name=submit value="Remove spaces">

</form>

</body>

</html>

I am tired. More later.

Leave a comment