article

Beginners guide [2] to ASP filled with examples!

Email
Submitted on: 1/6/2015 2:04:00 AM
By: snowboardr (from psc cd)  
Level: Beginner
User Rating: By 10 Users
Compatibility: ASP (Active Server Pages)
Views: 1330
 
     Here is my second tutorial in basic ASP scripting. Leave comments if you want. Or have questions.

 
				

Jason's Tutorial..



ASP - Active Server Pages [Tutorial 2] - Tutorial 1
Getting Scriptname

<%

'This is very useful, using this in your code will allow you to change the name of your page as much as you want without having to chang any source

ScriptName = Request.ServerVariables("SCRIPT_NAME")

Response.write(ScriptName)

%>

default.asp
Live Example at http://www.irideforlife.com/go/default2.asp

 

Redirect to url..

<%

Response.Redirect "http://www.planetsourcecode.com"

%>

 

Stop writing the page..

<%


Response.write "Hello there, this page needs to..."

Response.End
Response.write "Have an ending?"

%>

Hello there, this page needs to...
Live Example at http://www.irideforlife.com/go/default2.asp

 

Count the number of chr's in your string

<%

MyString = "1234567"


Response.write len(MyString)

%>

7
Live Example at http://www.irideforlife.com/go/default2.asp

 

Select Case

<%

MyCase = "3"

Select Case MyCase

Case 1

Response.write "its 1"

Case 2

Response.write "its 2"

Case 3

Response.write "its 3"

End Select

%>

Live Example at http://www.irideforlife.com/go/default2.asp

 

Select Case QueryString

<%

'<%= ScriptName & "?case=one" %>
'<%= ScriptName & "?case=two" %>
'<%= ScriptName & "?case=three"%>

TheCase = Request.QueryString("case")

Select Case TheCase

Case "one"

Response.write "its 1"

Case "two"

Response.write "its 2"

Case "three"

Response.write "its 3"

End Select

%>

Live Example at http://www.irideforlife.com/go/default2.asp

 

Writing m / dd/yyyy

<%

TheMonth = month(date)

TheDay = day(date)

TheYear = year(date)

Response.write(TheMonth) & "/" & TheDay & "/" & TheYear

' & Seperates each thing.

%>

Live Example at http://www.irideforlife.com/go/default2.asp

 

Writing HH:MM:SS

<%

TheHour = hour(time)

TheMinute = minute(time)

TheSecond = second(time)

Response.write(TheHour) & ":" & TheMinute & ":" & TheSecond

' & Seperates each thing.

%>

Live Example at http://www.irideforlife.com/go/default2.asp

 

 

Getting Form Results

<%

Dim age

age = Request.Form("age")

%>

<form name="form1" method="post" action="<%=ScriptName & "?submit=form" %>">
<table width="9%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">&lt;18</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="radio" name="age" value="<18" <% if age = "<18" then Response.write "checked" %> >
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">18-21</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="radio" name="age" value="18-21" <% if age = "18-21" then Response.write "checked" %> >
</font></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">22 &gt;</font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="radio" name="age" value="22>" <% if age = "22>" then Response.write "checked" %> >
</font></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Submit">
<%

If Request.QueryString("submit") = "form"

If NOT age = "" Then ' Lets make sure the form wasn't submited with nothing checked.

Response.write "You are in the " & age & " age range!

End If

End if

%>

</td>
</tr>
</table>
</form>

Live Example at http://www.irideforlife.com/go/default2.asp

 

 

 

Please post comments below and vote if this helped...thanks!

-Jason

 

 

 


Other 12 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.