Simple Tag Code Simple Tag Page

Welcome to the clock page

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 Change the Light <% if hour(Time) > 6 and Hour(Time) < 19 then Response.Write "" else Response.Write "" end if %>

We turn down the light at night.

Script Within Script Client and Server <% If Session("CustomerType") = "Preferred" then TheRate = 25 else TheRate = 50 end if %>
Enter Quantity to determine price

Include File <% Function DateRange(DateToTest, StartDate, EndDate) if not isdate(DateToTest) then DateRange = 0 elseif cdate(DateToTest) < cdate(StartDate) or _ cdate(DateToTest) > cdate(EndDate) then DateRange = 0 else DateRange = -1 end if End Function Function NumberRange(FieldToTest, MinNumber, MaxNumber) If Not IsNumeric(FieldToTest) Then NumberRange = 0 ElseIf CSng(FieldToTest) < MinNumber Or _ CSng(FieldToTest) > MaxNumber Then NumberRange = 0 Else NumberRange = -1 End If End Function Function Birthdate(FieldToTest) If Not IsDate(FieldToTest) Then Birthdate = 0 ElseIf CDate(FieldToTest) > Date Then Birthdate = 0 Else Birthdate = -1 End If End Function Function ZipCode(FieldToTest) If Len(FieldToTest) = 5 Then If IsNumeric(FieldToTest) Then ZipCode = -1 Else ZipCode = 0 End If ElseIf Len(FieldToTest) = 10 Then If IsNumeric(Left(FieldToTest, 5)) And _ IsNumeric(Right(FieldToTest, 4)) Then ZipCode = -1 Else ZipCode = 0 End If Else ZipCode = 0 End If End Function %> Convert It Function <% Function ConvertIt(StringToConvert, ReplaceChar, ConversionChar) If Instr(StringToCOnvert, ReplaceChar) then 'code to convert string goes here end if End Function %> Number Text Code <% If Request.QueryString("TheNumber") = 5 then Response.Write "" Response.Write "You are correct!
" Response.Write "
" else Response.Write "" Response.Write "Wrong!
" Response.Write "
" end if Response.Write "That's it" %> Sample If Block <% If Request.QueryString("TheAge") < 13 then Response.Write "You are a youngster" ElseIf Request.QueryString("TheAge") < 20 then Response.Write "You are a teenager" ElseIf Request.QueryString("TheAge") < 40 then Response.Write "You are a young adult" ElseIf Request.QueryString("TheAge") < 60 then Response.Write "You have the experience" Else Response.Write "You are having fun" End If %> Sample If Block 2 <% If Request.QueryString("TheAge") < 13 then Response.Write "You are a young " If Request.QueryString("Sex") = "Female" then Response.Write "girl" else Response.Write "boy" end if Response.Write "." ElseIf Request.QueryString("TheAge") < 20 then Response.Write "You are a teenager" ElseIf Request.QueryString("TheAge") < 40 then Response.Write "You are a young adult" ElseIf Request.QueryString("TheAge") < 60 then Response.Write "You have the experience" Else Response.Write "You are having fun" end if %> Select Code <% Select Case Request.QueryString("Quantity") Case 1 Response.Write "$50" Case 2 Response.Write "$90" Case 3 Response.Write "$130" Case 4 Response.Write "$150" Case Else Response.Write "$" & Request.QueryString("Quantity") * 40 End Select %> Loop Sample <% set conn = server.createobject ("adodb.connection") conn.open "Ecommerce", "sa", "yourpassword" set RSOrderItems = conn.Execute("select ItemID, " _ & "ItemName, ItemType, Quantity, TotalPrice, " _ & "DetailText from WIOrderItems where " _ & SessionID = " & Session("SessionID")) do until RSOrderItems.EOF %>

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 %>