Simple Tag Code
It is now: <% = Now() %>
Sample Code Block <% If WeekDay(Date) = 1 then Response.Redirect "Sunday.html" ElseIf WeekDay(Date) = 2 then Response.Redirect "Monday.html" ElseIf WeekDay(Date) = 3 then Response.Redirect "Tuesday.html" ElseIf WeekDay(Date) = 4 then Response.Redirect "Wednesday.html" ElseIf WeekDay(Date) = 5 then Response.Redirect "Thursday.html" ElseIf WeekDay(Date) = 6 then Response.Redirect "Friday.html" Else Response.Redirect "Saturday.html" End If %> HTML in Code
Item Name: <% Response.Write RSOrderItems("ItemType") %>
<% Response.Write RSOrderItems("ItemName") %>
Quantity: <% Response.Write RSOrderItems("Quantity") %>
Price: <% Response.Write RSOrderItems("TotalPrice") %>
<%
RSOrderItems.MoveNext
Loop
%>
For Each
<%
Option Explicit
Dim TheVariable
For Each TheVariable in Request.ServerVariables
Response.Write TheVariable & " - " _
& Request.ServerVariables(TheVariable) _
& "
"
Next
%>
Date Code
<%
Response.Write "Year: " & Year(Date) & "
"
Response.Write "Month Number: " & Month(Date) & "
"
Response.Write "Day of Month: " & Day(Date) & "
"
Response.Write "Weekday Number: " & WeekDay(Date) & "
"
Response.Write "Hour: " & Hour(Time) & "
"
Response.Write "Minute: " & Minute(Time) & "
"
Response.Write "Second: " & Second(Time) & "
"
%>
Log in Code
<%
if not isempty(Request.Form("LogIn")) then
set conn = server.createobject ("adodb.connection")
conn.open "ASPBook", "sa", "yourpassword"
set RSUser = conn.Execute("select UserName from C1Login " _
& "where UserName = '" & Request.Form("UserName") _
& "' and Password = '" & Request.Form("Password") _
& "'")
if RSUser.EOF then
TheMessage = "You have entered an incorrect login. " _
& "Please try again."
else
TheMessage = "You are now logged in!"
end if
else
TheMessage = "Please enter your user name and password below."
end if
%>
Date Validation
<%
Option Explicit
Dim TheMessage
If IsDate(Request.Form("BirthDate")) then
If Cdate(Request.Form("BirthDate")) <= Date then
TheMessage = "Value OK"
Else
TheMessage = "Birth date can not be in the future!"
End If
Else
TheMessage = "The value you entered is not a date"
End If
%>
<%
Option Explicit
Dim TheMessage
If IsDate(Request.Form("BirthDate")) then
If Cdate(Request.Form("BirthDate")) > Date then
TheMessage = "Birth date can not be in the future!"
ElseIf DateDiff("yyyy", Request.Form("BirthDate"), Date) > 150
TheMessage = "A valid birth date was not entered!"
Else
TheMessage = "Value OK"
End If
Else
TheMessage = "The value you entered is not a date"
End If
%>
Number Testing
<%
Option Explicit
Dim TheMessage
If IsNumeirc(Request.Form("Quantity")) then
If CInt(Request.Form("Quantity")) < 1 then
TheMessage = "You must order at least one item!"
ElseIf CInt(Request.Form("Quantity")) > 250 then
TheMessage = "Quantity can not be 250 or above!"
Else
TheMessage = "Order Added"
End If
Else
TheMessage = "Quantity must be a number!"
End If
%>
Format Function
<%
Response.Write "General Format (Default): "
Response.Write FormatDateTime(Now,0) & "
" Response.Write "Long Date: " Response.Write FormatDateTime(Now,1) & "
" Response.Write "Short Date: " Response.Write FormatDateTime(Now,2) & "
" Response.Write "Long Time: " Response.Write FormatDateTime(Now,3) & "
" Response.Write "Short Time: " Response.Write FormatDateTime(Now,4) %> <% Response.Write FormatCurrency(12345.67) & "
" Response.Write FormatCurrency(-12345.67) & "
" Response.Write FormatCurrency(12345.67,3) & "
" Response.Write FormatCurrency(.67, ,0) & "
" Response.Write FormatCurrency(-12345.67,,,0) & "
" Response.Write FormatCurrency(12345.67,,,,0) & "
" %> <% Response.Write FormatNumber(.67) & "
" Response.Write FormatNumber(-12345.67) & "
" Response.Write FormatNumber(12345.67123456,5) & "
" Response.Write FormatNumber(.67, ,0) & "
" Response.Write FormatNumber(-12345.67,,,0) & "
" Response.Write FormatNumber(987654321.1234,,,,0) & "
" %> <% Response.Write FormatPercent(.67) & "
" Response.Write FormatPercent(-.67) & "
" Response.Write FormatPercent(23.67) & "
" Response.Write FormatPercent(23.67, 0) & "
" %> Instr Function <% Option Explicit Dim String2Search Dim SearchString String2Search = "Mississippi" SearchString = "s" Response.Write Instr(String2Search, SearchString) '3 is written to the browser Response.Write Instr(3, String2Search, SearchString) '3 is still written to the browser since 3 is the starting point Response.Write Instr(5, String2Search, SearchString) '6 is written to the browser SearchString = "Z" Response.Write Instr(String2Search, SearchString) 'since the string is not found 0 is written SearchString = "P" Response.Write Instr(String2Search, SearchString) '0 again since case is sensitive Response.Write Instr(1 ,String2Search, SearchString, 1) 'Text comparison so 9 is written to the browser %> InstrRev <% Option Explicit Dim String2Search Dim SearchString String2Search = "Mississippi" SearchString = "s" Response.Write InstrRev(String2Search, SearchString) %> Email Validation <% Option Explicit Dim TheAt Dim TheDot Dim FieldToTest FieldToTest = "bob@somewhere.com" If Len(FieldToTest) < 6 then Response.Write "Email Address Invalid!" Else TheAt = InStr(2, FieldToTest, "@") If TheAt = 0 Then Response.Write "Email Address Invalid!" Else TheDot = InStr(cint(TheAt) + 2, FieldToTest, ".") If TheDot = 0 Then Response.Write "Email Address Invalid!" ElseIf cint(TheDot) + 1 > Len(FieldToTest) Then Response.Write "Email Address Invalid!" Else Response.Write "Email Address is valid!" End If End If End If %> Replace <% 'normal replace Response.Write Replace("Mississippi", "s", "x") & "
" 'start at position number 5 Response.Write Replace("Mississippi", "s", "x", 5) & "
" 'start at position 1 and make to replacements Response.Write Replace("Mississippi", "s", "x", 1, 2) & "
" 'start at position 4 and make two replacements Response.Write Replace("Mississippi", "s", "x", 4, 2) & "
" 'standard replace but character not found Response.Write Replace("Mississippi", "S", "x") & "
"
'same test but now a text comparison
Response.Write Replace("Mississippi", "S", "x", 1, 4, 1)
%>
Random Number
<%
Option Explicit
Randomize
Dim I
For I = 1 to 10
Response.Write Int((Rnd * 30) + 20) & "
"
Next
%>
Email Address Validation
<%
Option Explicit
Dim LocalTest
LocalTest = "mary@somewhere.com"
Response.Write ValidateEmailAddress(LocalTest)
%>
<%
Function ValidateEmailAddress(FieldToTest)
Dim TheAt
Dim TheDot
If Len(FieldToTest) < 6 then
ValidateEmailAddress = "Email Address Invalid!"
Else
TheAt = InStr(2, FieldToTest, "@")
If TheAt = 0 Then
ValidateEmailAddress = "Email Address Invalid!"
Else
TheDot = InStr(cint(TheAt) + 2, FieldToTest, ".")
If TheDot = 0 Then
ValidateEmailAddress = "Email Address Invalid!"
ElseIf cint(TheDot) + 1 > Len(FieldToTest) Then
ValidateEmailAddress = "Email Address Invalid!"
Else
ValidateEmailAddress = "Email Address is valid!"
End If
End If
End If
End Sub
%>