<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
%>
<%
Set FS=Server.CreateObject("Scripting.FileSystemObject")
Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 1, False)
fcount=RS.ReadLine
RS.Close
fcount=fcount+1
'This code is disabled due to the write access security on our server:
'Set RS=FS.OpenTextFile(Server.MapPath("counter.txt"), 2, False)
'RS.Write fcount
'RS.Close
Set RS=Nothing
Set FS=Nothing
%>
<%
dim numvisits
response.cookies("NumVisits").Expires=date+365
numvisits=request.cookies("NumVisits")
if numvisits="" then
response.cookies("NumVisits")=1
response.write("Welcome! This is the first time you are visiting this Web page.")
else
response.cookies("NumVisits")=numvisits+1
response.write("You have visited this ")
response.write("Web page " & numvisits)
if numvisits=1 then
response.write " time before!"
else
response.write " times before!"
end if
end if
%>
<%
Response.ContentType="text/html"
%>
<%
Response.Charset="ISO8859-1"
%>
<%
dim numvisits
response.cookies("NumVisits").Expires=date+365
numvisits=request.cookies("NumVisits")
if numvisits="" then
response.cookies("NumVisits")=1
response.write("Welcome! This is the first time you are visiting this Web page.")
else
response.cookies("NumVisits")=numvisits+1
response.write("You have visited this ")
response.write("Web page " & numvisits)
if numvisits=1 then
response.write " time before!"
else
response.write " times before!"
end if
end if
%>
<%@ language="javascript" %>
<%
if Request.Form("select")<>"" then
Response.Redirect(Request.Form("select"))
end if
%>
<%
Response.Buffer=true
%>
<%Response.Expires=-1%>
<%
Response.ExpiresAbsolute=#May 05,2001 05:30:30#
%>
<%
dim cars
cars=Request.Form("cars")
%>
<%
sub vbproc(num1,num2)
response.write(num1*num2)
end sub
%>
<%
function jsproc(num1,num2)
{
Response.Write(num1*num2)
}
%>
<%
sub vbproc(num1,num2)
Response.Write(num1*num2)
end sub
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.name)
Response.Write(" = ")
Response.Write(x.value & "
")
rs.MoveNext
loop
rs.close
conn.close
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers WHERE CompanyName LIKE 'A%'"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers WHERE CompanyName>'E'"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers WHERE Country='Spain'"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT Country FROM Customers ORDER BY Country"
rs.Open sql,conn
country=request.form("country")
%>
<%
if country<>"" then
sql="SELECT Companyname,Contactname,Country FROM Customers WHERE country='" & country & "'"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
%>
<% end if %>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
sql="SELECT Companyname, Contactname FROM Customers ORDER BY CompanyName DESC"
rs.Open sql, conn
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
'The first number indicates how many records to copy
'The second number indicates what recordnumber to start on
p=rs.GetRows(2,0)
response.write("
")
response.write(p(2,0))
rs.close
conn.close
%>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "SELECT Companyname, Contactname FROM Customers", conn
str=rs.GetString(,,"
"," ")
%>
<%
rs.close
conn.close
set rs = Nothing
set conn = Nothing
%>
This is page 1!
<%
Set nl=Server.CreateObject("MSWC.NextLink")
If (nl.GetListIndex("text/links2.txt")>1) Then
%>
">Previous Page
<%End If%>
">Next Page
The example uses the Content Linking Component
to navigate between the pages in a text file.
The example below builds a table of contents.
<%
dim c
dim i
set nl=server.createobject("MSWC.Nextlink")
c = nl.GetListCount("text\links.txt")
i = 1
%>
The text file contains a list of page urls
and link descriptions. It contains one line of text for each page. Note that the url and
description MUST be separated by the TAB character.
<%
set cr=server.createobject("MSWC.ContentRotator")
response.write(cr.ChooseContent("text/textads.txt"))
%>
NOTE: Because the content strings are changed randomly in the text file, and this page has only four content strings to choose from, sometimes the page will display the same content strings twice in a row.
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
| Client OS |
<%=MyBrow.platform%> |
| Web Browser |
<%=MyBrow.browser%> |
| Browser version |
<%=MyBrow.version%> |
| Frame support? |
<%=MyBrow.frames%> |
| Table support? |
<%=MyBrow.tables%> |
| Sound support? |
<%=MyBrow.backgroundsounds%> |
| Cookies support? |
<%=MyBrow.cookies%> |
| VBScript support? |
<%=MyBrow.vbscript%> |
| JavaScript support? |
<%=MyBrow.javascript%> |
<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.TargetFrame="target='_blank'"
response.write(adrotator.GetAdvertisement("text/advertisements.txt"))
%>
NOTE: Because images are changed randomly, and because this page has few images to choose from, it will
often display the same advertisement twice in a row.
NOTE: The AdRotator does not work with Internet Information Server 7 (IIS7).
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If (fs.FileExists("c:\winnt\cursors\3dgarro.cur"))=true Then
Response.Write("File c:\winnt\cursors\3dgarro.cur exists.")
Else
Response.Write("File c:\winnt\cursors\3dgarro.cur does not exist.")
End If
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If fs.FolderExists("c:\temp") = true Then
Response.Write("Folder c:\temp exists.")
Else
Response.Write("Folder c:\temp does not exist.")
End If
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.driveexists("c:") = true then
Response.Write("Drive c: exists.")
Else
Response.Write("Drive c: does not exist.")
End If
Response.write(" ")
if fs.driveexists("g:") = true then
Response.Write("Drive g: exists.")
Else
Response.Write("Drive g: does not exist.")
End If
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetDriveName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The drive name is: " & p)
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
if fs.driveexists("c:") = true then
Response.Write("Drive c: exists.")
Else
Response.Write("Drive c: does not exist.")
End If
Response.write(" ")
if fs.driveexists("g:") = true then
Response.Write("Drive g: exists.")
Else
Response.Write("Drive g: does not exist.")
End If
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The parent folder name of c:\winnt\cursors\3dgarro.cur is: " & p)
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Response.Write("The file extension of the file 3dgarro is: ")
Response.Write(fs.GetExtensionName("c:\winnt\cursors\3dgarro.cur"))
set fs=nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Response.Write(fs.GetBaseName("c:\winnt\cursors\3dgarro.cur"))
Response.Write(" ")
Response.Write(fs.GetBaseName("c:\winnt\cursors\"))
Response.Write(" ")
Response.Write(fs.GetBaseName("c:\winnt\"))
set fs=nothing
%>
This is the text in the text file:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
This is the first five characters from the text file:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.Read(5))
f.Close
Set f=Nothing
Set fs=Nothing
%>
This is the first line of the text file:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.ReadLine)
f.Close
Set f=Nothing
Set fs=Nothing
%>
This is all the lines in the text file:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
do while f.AtEndOfStream = false
Response.Write(f.ReadLine)
Response.Write(" ")
loop
f.Close
Set f=Nothing
Set fs=Nothing
%>
The first four characters in the text file are skipped:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
f.Skip(4)
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
The first line in the text file is skipped:
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
f.SkipLine
Response.Write(f.ReadAll)
f.Close
Set f=Nothing
Set fs=Nothing
%>
This is all the lines in the text file (with line numbers):
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
do while f.AtEndOfStream = false
Response.Write("Line:" & f.Line & " ")
Response.Write(f.ReadLine)
Response.Write(" ")
loop
f.Close
Set f=Nothing
Set fs=Nothing
%>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(Server.MapPath("testread.txt"), 1)
Response.Write(f.Read(2))
Response.Write("The cursor is now standing in position " & f.Column & " in the text file. ")
f.Close
Set f=Nothing
Set fs=Nothing
%>
<%
Dim fs, d, n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & " Available Space in bytes: " & d.AvailableSpace
Response.Write(n)
set d=nothing
set fs=nothing
%>
<%
Dim fs, d, n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & " Free Space in bytes: " & d.FreeSpace
Response.Write(n)
set d=nothing
set fs=nothing
%>
<%
Dim fs,d,n
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set d=fs.GetDrive("c:")
n = "Drive: " & d
n = n & " Total size in bytes: " & d.TotalSize
Response.Write(n)
set d=nothing
set fs=nothing
%>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The drive letter is: " & d.driveletter)
set d=nothing
set fs=nothing
%>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The drive type is: " & d.DriveType)
set d=nothing
set fs=nothing
%>
<%
dim fs, d, n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The file system is: " & d.FileSystem)
set d=nothing
set fs=nothing
%>
<%
dim fs,d,n
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
n = "The " & d.DriveLetter
if d.IsReady=true then
n = n & " drive is ready."
else
n = n & " drive is not ready."
end if
Response.Write(n)
set d=nothing
set fs=nothing
%>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The path is " & d.Path)
set d=nothing
set fs=nothing
%>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The rootfolder is " & d.RootFolder)
set d=nothing
set fs=nothing
%>
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The serialnumber is " & d.SerialNumber)
set d=nothing
set fs=nothing
%>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was created on: " & f.DateCreated)
set f=nothing
set fs=nothing
%>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last modified on: " & f.DateLastModified)
set f=nothing
set fs=nothing
%>
<%
dim fs, f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The file testread.txt was last accessed on: " & f.DateLastAccessed)
set f=nothing
set fs=nothing
%>
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile(Server.MapPath("testread.txt"))
Response.Write("The attributes of the file testread.txt are: " & f.Attributes)
set f=nothing
set fs=nothing
%>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
if d.Exists("n")= true then
Response.Write("Key exists.")
else
Response.Write("Key does not exist.")
end if
set d=nothing
%>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The values of the items are: ")
a=d.Items
for i = 0 To d.Count -1
s = s & a(i) & " "
next
Response.Write(s)
set d=nothing
%>
<%
dim d,a,i,s
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The value of the keys are: ")
a=d.Keys
for i = 0 To d.Count -1
s = s & a(i) & " "
next
Response.Write(s)
set d=nothing
%>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The value of the item n is: " & d.item("n"))
set d=nothing
%>
<%
dim d
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
d.Key("i") = "it"
Response.Write("The key i has been set to it, and the value is: " & d.Item("it"))
set d=nothing
%>
<%
dim d, a, s, i
set d=Server.CreateObject("Scripting.Dictionary")
d.Add "n", "Norway"
d.Add "i", "Italy"
Response.Write("The number of key/item pairs is: " & d.Count)
set d=nothing
%>
This page has been visited <%=fcount%> times.
<%
Response.Write(Session.SessionID)
%>
<%
response.write("")
response.write("Default Timeout is: " & Session.Timeout & " minutes.")
response.write(" ")
Session.Timeout=30
response.write("")
response.write("Timeout is now: " & Session.Timeout & " minutes.")
response.write(" ")
%>
<%
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp"))
modified = rs.DateLastModified
%>
This file was last modified on: <%response.write(modified)
Set rs = Nothing
Set fs = Nothing
%>
<%
Set FS = Server.CreateObject("Scripting.FileSystemObject")
Set RS = FS.OpenTextFile(Server.MapPath("text") & "\TextFile.txt",1)
While not rs.AtEndOfStream
Response.Write RS.ReadLine
Response.Write(" ")
Wend
%>
This is some text
Example
<%
Response.Write(Request.QueryString)
%>
This is some text
ASP Source:
<%
If Request.Form("txt")<>"" Then
Response.Write("You submitted: ")
Response.Write(Request.Form)
Response.Write("
")
Response.Write("Total bytes: ")
Response.Write(Request.Totalbytes)
End If
%>
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "! ")
Response.Write("How are you today?")
End If
%>
<%
Response.Write(Request.QueryString)
%>
<%
If Request.QueryString<>"" Then
If Request.QueryString("name")<>", " Then
name=Request.QueryString("name")
if instr(name,"/")=0 and instr(name,"\")=0 and instr(name,"<")=0 then
name1=Request.QueryString("name")(1)
name2=Request.QueryString("name")(2)
else
response.write("Illegal input")
response.end
end if
end if
end if
%>
<%
If Request.QueryString<>"" Then
Response.Write("")
Response.Write("The information received from the form was:")
Response.Write(" ")
Response.Write("name=" & name)
Response.Write(" ")
Response.Write("The name property's count is: ")
Response.Write(Request.QueryString("name").Count)
Response.Write(" ")
Response.Write("First name=" & name1)
Response.Write(" ")
Response.Write("Last name=" & name2)
Response.Write(" ")
end if
%>
<%
Response.Write(Request.Form)
%>
<%
dim fname
fname=Request.Form("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "! ")
Response.Write("How are you today?")
End If
%>
The information received from the form above was:
<%
If Request.Form("name")<>"" Then
Response.Write("")
Response.Write("name=" & Request.Form("name"))
Response.Write(" ")
Response.Write("The name property's count is: ")
Response.Write(Request.Form("name").Count)
Response.Write(" ")
Response.Write("First name=" & Request.Form("name")(1))
Response.Write(" ")
Response.Write("Last name=" & Request.Form("name")(2))
Response.Write(" ")
End if
%>
<%
dim cars
cars=Request.Form("cars")
%>
<%
if cars<>"" then
Response.Write("Your favorite car is: " & cars & " ")
end if
%>
<%
fruits=Request.Form("fruits")
%>
<%
if fruits<>"" then%>
You like: <%Response.Write(fruits)%>
<%end if
%>
You are browsing this site with:
<%Response.Write(Request.ServerVariables("http_user_agent"))%>
Your IP address is:
<%Response.Write(Request.ServerVariables("remote_addr"))%>
The DNS lookup of the IP address is:
<%Response.Write(Request.ServerVariables("remote_host"))%>
The method used to call the page:
<%Response.Write(Request.ServerVariables("request_method"))%>
The server's domain name:
<%Response.Write(Request.ServerVariables("server_name"))%>
The server's port:
<%Response.Write(Request.ServerVariables("server_port"))%>
The server's software:
<%Response.Write(Request.ServerVariables("server_software"))%>
All possible server variables:
<%
For Each Item in Request.ServerVariables
Response.Write(Item & " ")
Next
%>
This is some text
<%
If Response.IsClientConnected=true then
Response.Write("The user is still connected!")
else
Response.Write("The user is not connected!")
end if
%>
This page will expire on May 05, 2001 05:30:30!
This page will be refreshed with each access!
This text will be sent to your browser when my response buffer is flushed.
<%
Response.Flush
%>
This is some text I want to send to the user.
No, I changed my mind. I want to clear the text.
<%
Response.Clear
%>
I am writing some text. This text will never be <%
Response.End
%>
finished! It's too late to write more!
<%
randomize()
r=rnd()
if r>0.5 then
response.write("W3Schools.com!")
else
response.write("Refsnesdata.no!")
end if
%>
This example demonstrates a link, each time you load the page, it will display
one of two links: W3Schools.com! OR Refsnesdata.no! There is a 50% chance for
each of them.
ASP can output plain text:
<%response.write("Hello World!")%>
<%
response.write("You can use HTML tags to format the text!")
%>
<%
response.write("This text is styled with the style attribute! ")
%>
<%
if cars<>"" then
Response.Write("Your favorite car is: " & cars & " ")
end if
%>
<%
var d=new Date()
var h=d.getHours()
Response.Write("")
Response.Write(d)
Response.Write(" ")
if (h<12)
{
Response.Write("Good Morning!")
}
else
{
Response.Write("Good day!")
}
%>
<%
i=hour(time)
If i < 10 Then
response.write("Good morning!")
Else
response.write("Have a nice day!")
End If
%>
<%
i=hour(time)
If i = 10 Then
response.write("Just started...!")
ElseIf i = 11 Then
response.write("Hungry!")
ElseIf i = 12 Then
response.write("Ah, lunch-time!")
ElseIf i = 16 Then
response.write("Time to go home!")
Else
response.write("Unknown")
End If
%>
<%
d=weekday(Date)
Select Case d
Case 1
response.write("Sleepy Sunday")
Case 2
response.write("Monday again!")
Case 3
response.write("Just Tuesday!")
Case 4
response.write("Wednesday!")
Case 5
response.write("Thursday...")
Case 6
response.write("Finally Friday!")
Case Else
response.write("Super Saturday!!!!")
End Select
%>
This example demonstrates the "Select Case" statement.
You will receive a different greeting based on what day it is.
Note that Sunday=1, Monday=2, Tuesday=3, etc.
<%
randomize()
r=rnd()
If r>0.5 Then
response.write("Learn XML!")
Else
response.write("Learn PHP!")
End If
%>
This example demonstrates a link, when you click on the link it will take you to XML or to
PHP. There is a 50% chance for each of them.
ASP Source:
<%
dim fname
fname=Request.QueryString("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "! ")
Response.Write("How are you today?")
End If
%>
<%
dim fname
fname=Request.Form("fname")
If fname<>"" Then
Response.Write("Hello " & fname & "! ")
Response.Write("How are you today?")
End If
%>
<%
dim h
h=hour(now())
response.write("" & now())
response.write(" ")
If h<12 then
response.write("Good Morning!")
else
response.write("Good day!")
end if
%>
Result: <%call vbproc(3,4)%>
Result: <%call jsproc(3,4)%>
Result: <%jsproc(3,4)%>
You can call a procedure like this:
Result: <%call vbproc(3,4)%>
Or, like this:
Result: <%vbproc 3,4%>
Today's date is: <%response.write(date())%>.
The server's local time is: <%response.write(time())%>.
VBScripts' function WeekdayName is used to get a weekday:
<%
response.Write(WeekDayName(1))
response.Write(" ")
response.Write(WeekDayName(2))
%>
Abbreviated name of a weekday:
<%
response.Write(WeekDayName(1,true))
response.Write(" ")
response.Write(WeekDayName(2,true))
%>
Current weekday:
<%
response.Write(WeekdayName(weekday(date)))
response.Write(" ")
response.Write(WeekdayName(weekday(date), true))
%>
VBScripts' function MonthName is used to get a month:
<%
response.Write(MonthName(1))
response.Write(" ")
response.Write(MonthName(2))
%>
Abbreviated name of a month:
<%
response.Write(MonthName(1,true))
response.Write(" ")
response.Write(MonthName(2,true))
%>
Current month:
<%
response.Write(MonthName(month(date)))
response.Write(" ")
response.Write(MonthName(month(date), true))
%>
Today it is
<%response.write(WeekdayName(weekday(date)))%>,
and the month is
<%response.write(MonthName(month(date)))%>
Countdown to year 3000:
<%millennium=cdate("1/1/3000 00:00:00")%>
It is
<%response.write(DateDiff("yyyy", Now(), millennium))%>
years to year 3000!
It is
<%response.write(DateDiff("m", Now(), millennium))%>
months to year 3000!
It is
<%response.write(DateDiff("ww", Now(), millennium))%>
weeks to year 3000!
It is
<%response.write(DateDiff("d", Now(), millennium))%>
days to year 3000!
It is
<%response.write(DateDiff("h", Now(), millennium))%>
hours to year 3000!
It is
<%response.write(DateDiff("n", Now(), millennium))%>
minutes to year 3000!
It is
<%response.write(DateDiff("s", Now(), millennium))%>
seconds to year 3000!
<%
response.write(FormatDateTime(date(),vbgeneraldate))
response.write(" ")
response.write(FormatDateTime(date(),vblongdate))
response.write(" ")
response.write(FormatDateTime(date(),vbshortdate))
response.write(" ")
response.write(FormatDateTime(now(),vblongtime))
response.write(" ")
response.write(FormatDateTime(now(),vbshorttime))
%>
Syntax for FormatDateTime: FormatDateTime(date,namedformat).
<%
response.write(DateAdd("d",30,Date()))
%>
This example uses DateAdd to calculate a date 30 days from today.
Syntax for DateAdd: DateAdd(interval,number,date).
<%
somedate="10/30/99"
response.write(IsDate(somedate))
%>
<%
name = "Bill Gates"
response.write(ucase(name))
response.write(" ")
response.write(lcase(name))
%>
<%
name = " W3Schools "
response.write("visit" & name & "now ")
response.write("visit" & trim(name) & "now ")
response.write("visit" & ltrim(name) & "now ")
response.write("visit" & rtrim(name) & "now")
%>
<%
sometext = "Hello Everyone!"
response.write(strReverse(sometext))
%>
<%
i = 48.66776677
j = 48.3333333
response.write(Round(i))
response.write(" ")
response.write(Round(j))
%>
<%
randomize()
response.write(rnd())
%>
<%
Randomize()
randomNumber=Int(100 * Rnd())
response.write("A random number: " & randomNumber & "")
%>
<%
sometext="Welcome to this Web"
response.write(Left(sometext,5))
response.write(" ")
response.write(Right(sometext,5))
%>
<%
sometext="Welcome to this Web!!"
response.write(Replace(sometext, "Web", "Page"))
%>
<%
sometext="Welcome to this Web!!"
response.write(Mid(sometext, 9, 2))
%>
<%
Sub mysub()
response.write("I was written by a sub procedure")
End Sub
response.write("I was written by the script ")
Call mysub()
%>
<%
Function myfunction()
myfunction=Date()
End Function
response.write("Today's date: ")
response.write(myfunction())
%>
A Function procedure can return a result.
ASP can output plain text:
<%response.write("Hello World!")%>
ASP can output HTML tags as well as plain text:
<%
response.write("Hello World!")
%>
ASP can output HTML attributes as well as plain text:
<%
response.write("This text is styled. ")
%>
<%
dim name
name="Donald Duck"
response.write("My name is: " & name)
%>
<%
Dim firstname
firstname="Hege"
response.write(firstname)
response.write(" ")
firstname="Tove"
response.write(firstname)
%>
The script above declares a variable, assigns a value to it, and displays the value. Then, it changes the value, and displays the value again.
<%
Dim name
name="Jan Egil"
response.write("My name is: " & name)
%>
<%
Dim famname(5),i
famname(0) = "Jan Egil"
famname(1) = "Tove"
famname(2) = "Hege"
famname(3) = "Stale"
famname(4) = "Kai Jim"
famname(5) = "Borge"
For i = 0 to 5
response.write(famname(i) & " ")
Next
%>
<%
For i = 0 To 5
response.write("The number is " & i & " ")
Next
%>
<%
dim i
for i=1 to 6
response.write("Heading " & i & "")
next
%>
<%
Dim cars(2)
cars(0)="Volvo"
cars(1)="Saab"
cars(2)="BMW"
For Each x In cars
response.write(x & " ")
Next
%>
<%
i=0
Do While i < 10
response.write(i & " ")
i=i+1
Loop
%>
Style Hello World! Change text Tôi học tiếng Hàn URL: Tôi học tiếng Hàn A rela...
|