AdRotator

Keywords: asp, AdRotator, banners
'(1) AD ROTATOR COMPONENT (ADROT.TXT)
Redirect /adredir.asp
Width 230
Height 45
Border 0
*
images/banner1.gif
http://www.test1.com
Test 1
33
images/banner2.gif
http://www.test2.com
Test 2
33
images/banner3.gif
http://www.test3.org
Test 3
33

'(2) AD ROTATOR COMPONENT (ADREDIR.ASP)
<%
Response.Buffer = True

Dim m_sURL
m_sURL = Request("url")
Response.Redirect(m_sURL)
%>

'(3) AD ROTATOR COMPONENT (ADPAGE.ASP)
<%
Dim m_oAdRotator
Set m_oAdRotator = Server.CreateObject("MSWC.AdRotator")
m_oAdRotator.TargetFrame = "TARGET=new"
Set m_oAdRotator = Nothing
%>

<%= m_oAdRotator.GetAdvertisement("adrot.txt") %>

Application Object

Keywords: asp, application object
<%
Dim f_sCompanyName : f_sCompanyName = Application("CompanyName")
%>

Array: Check if Empty

Keywords: asp, array, empty check
<%
Dim f_aArr(2)

f_bFound = False

For i = 0 To Ubound(f_aArr)
	If f_aArr(i) <> "" Then
		f_bFound = True
		Exit For
	End If
Next

If Not f_bFound Then
	Response.Write("Empty Array")
Else
	Response.Write("Not Empty")
End If
%>

Array: Count Elements

Keywords: asp, array, count
<%
If IsArray(f_aArr) = False Then 
	f_iVar = 0
Else
	f_iVar = (UBound(f_aArr) - LBound(f_aArr)) + 1
End If
%>

Array: Display Content

Keywords: asp, array, display
<%
Dim f_sNames : f_sNames = "Adam, Bill, Charlie"

f_sNameArray = split(f_sNames, ",")

For i = 0 To Ubound(f_sNameArray)
Response.Write(f_sNameArray(i) & "<br>")
Next
%>

Array: Replace

Keywords: asp, array, replace
<%
'Check text for URLs and make them clickable

Dim f_sTextBody : f_sTextBody = "Here is a link - www.test.com."

f_sArray = Split(f_sTextBody, " ")

For i = 0 To UBound(f_sArray)
	If Lcase(Left(f_sArray(i), 7)) = "http://" Then
		f_sArray(i) = "<a href='" & f_sArray(i) & "'>" & _
		f_sArray(i) & "</a>"
	End If

	If Lcase(Left(f_sArray(i), 3)) = "www" Then
		f_sArray(i) = "<a href='http://" & f_sArray(i) & "'>" & _
		f_sArray(i) & "</a>"
	End If
Next
		
f_sTextBody = Join(f_sArray, " ")
%>

Array: Word Count

Keywords: asp, array, word count, UBound, split
<%
Function GetWordCount(var)
	GetWordCount = UBound(Split(var, " ", -1, 1)) + 1
End Function
%>

ASPHTTP Object

Keywords: asp, http object
<%
Sub WebServ_Login()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Calls login web service using ASPHTTP.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim f_oASPHTTP

Set f_oASPHTTP = Server.CreateObject("AspHTTP.Conn")
f_oASPHTTP.Url = "http://www.website.com/Interact.asp?F=Login&User=jsmith&Password=222222"
f_oASPHTTP.RequestMethod = "Get"

Response.Write f_oASPHTTP.GetURL

Set f_oASPHTTP = Nothing
End Sub
%>

Authentication: Simple Login

Keywords: asp, authentication, simple login

' login.asp

<form method="post" action="verify.asp">
<table>
 <tr>
  <td>User Name:</td>
  <td><input type="text" name="username" size="20" maxlength="20"></td>
 <tr>
  <td>Password:</td>
  <td><input type="password" name="password" size="20" maxlength="20"></td>
 </tr>
 <tr><td colspan="2" align="center"><input type="submit" value="Login!"></td></tr>
</table>
</form>

<%
' verify.asp
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "cjDSN"

sqlString = "SELECT * FROM USERS WHERE " & "username='" & Trim(Request.Form("username")) & "' AND " & "password='" & Trim(Request.Form("password")) & "' "
Set RS = objCon.Execute(sqlString)

If RS.EOF Then
 Session("Authenticated") = 0
 Response.Redirect ("login.asp")
Else
 Session("Authenticated") = 1
 Response.Redirect ("index.asp")
End If

RS.Close
objCon.Close

Set RS = Nothing
Set objCon = Nothing
%>

<%
' includelogin.asp
If Session("Authenticated") = 0 Then
 Response.Redirect ("login.asp")
End If
%>

Authentication: Simple Login: No DB

Keywords: asp, authentication, simple login, no DB

SIMPLE LOGIN

<%
' includelogin.asp

Function ValidateLogin(sId, sPwd)
 ValidateLogin = False
 If sId = "admin" And sPwd="admin" Then
  ValidateLogin = True
 ElseIf sId = "demo" And sPwd="12345" Then
  ValidateLogin = True
 End If
End Function

Dim sText, fBack
fBack = False
If Request.Form("dologin") = "yes" Then
 IF ValidateLogin(Request.Form("id"), Request.Form("pwd")) = True Then 
  fBack = True
  Session("logonid") = Request.Form("id")
 Else
  sText = "Wrong password or user id"
 End If
Else
 If Session("logonid") <> "" Then
  fBack = True 
 Else
  sText = "Please login"
 End If
End If

If fBack = False Then
 Dim sURL
 sURL = Request.ServerVariables("SCRIPT_NAME")
 If Request.ServerVariables("QUERY_STRING") <> "" Then
  sURL = sURL & "?" & Request.ServerVariables("QUERY_STRING")
 End If
%>
 <form method="post" action="<%= sURL %>">
 <table>
 <tr>
 <td>User Name:</td>
 <td><input type="text" name="id" size="20"></td>
 </tr>
 <tr>
 <td>Password:</td>
 <td><input type="password" name="pwd" width="20"></td>
 </tr>
 <tr>
 <td colspan="2" align="center"><input type="submit" value="Login!"></td>
 </tr>
 <tr>
 <td colspan="2" align="center"><%= sText %></td>
 </tr>
 <input type="hidden" name="dologin" value="yes">
 </table>
 </form>
<%
 Response.End
End If
%>

Browser Hawk

Keywords: asp, browser hawk, cyScape, cookies enabled, javascript enabled

<%
Sub BrowserInfo_Get()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Grabs user browser info using BrowserHawk.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim f_oBrowserHawk
Dim f_sVersion, f_sBrowser

Set f_oBrowserHawk = Server.CreateObject("cyScape.browserObj")

' (1) detect cookies enabled
f_oBrowserHawk.CookieDetector "noredirect"
If Not f_oBrowserHawk.CookiesEnabled Then
If m_bAllow <> True Then
Response.Redirect("feedback_nocookie.asp?Disabled=Cookies")
Else
m_sCookies = Get_Text(lang, "feedback_no")
End If
Else
m_sCookies = Get_Text(lang, "feedback_yes")
End If

' (2) detect java script
f_oBrowserHawk.GetExtProperties
If Not f_oBrowserHawk.JavascriptEnabled Then
If m_bAllow <> True Then
Response.Redirect("feedback_nocookie.asp?Disabled=JavaScript")
Else
m_sJavaScript = Get_Text(lang, "feedback_no")
End If
Else
m_sJavaScript = Get_Text(lang, "feedback_yes")
End If

' (3) detect browser
f_sVersion = f_oBrowserHawk.Version
f_sBrowser = f_oBrowserHawk.Browser
m_sBrowserType = f_sBrowser & " " & f_sVersion

' (4) detect screen res
m_sResWidth = f_oBrowserHawk.Width
m_sResHeight = f_oBrowserHawk.Height

' (5) detect operating system
m_sPlatform = f_oBrowserHawk.Platform

' (6) detect proxy
m_bProxy = f_oBrowserHawk.Proxy

' (7) detect AOL
m_bAOL = f_oBrowserHawk.Aol

' Dispose
Set f_oBrowserHawk = Nothing
End Sub
%>

Browser: BrowsCap

Keywords: asp, browser, BrowsCap, browser type, MSWC
<%
Set f_oBC = Server.CreateObject("MSWC.BrowserType")

f_sBrowserName = f_oBC.browser
f_sBrowserVersion = f_oBC.version
f_sBrowserJavaScript = f_oBC.javascript
f_sBrowserCookies = f_oBC.cookies
f_sBrowserPlatform = f_oBC.platform

Set f_oBC = Nothing
%>

Class

Keywords: asp, class, object

<%          
Option Explicit

Class Developer
 Private m_sName
 Private m_iAge
 
 Public Property Let Name(ByVal vNewValue)
  m_sName = (vNewValue)
 End Property
              
 Public Property Get Name()
  Name = m_sName
 End Property
              
 Public Property Let Age(ByVal vNewValue)
  m_iAge = (vNewValue)
 End Property
         
 Public Function Age_Days()
  On Error Resume Next
        
  Dim f_sDate : f_sDate = Date()
  Dim f_sBDay : f_sBDay = "08/18/" & Year(f_sDate)
  Dim f_iDiff : f_iDiff = DateDiff("d", f_sBDay, f_sDate) 
             
  Age_Days = (m_iAge * 365) + Abs(f_iDiff)
 End Function
End Class
%>     

 
<%
Call Main()

Sub Main()
 Dim objDeveloper : Set objDeveloper = New Developer
 objDeveloper.Name = "Charles"
 objDeveloper.Age = 32
 Response.Write(objDeveloper.Name)
 Response.Write("<br>")
 Response.Write(objDeveloper.Age_Days)
End Sub 
%>

Cookies: List

Keywords: asp, cookies, list
<%
For Each cookie In Request.Cookies
	Response.Write "<b>" & cookie & ": </b> " & Request.Cookies(cookie) & "<br>"
Next
%>

Cookies: Set/Get

Keywords: asp, cookies
<%
Response.Cookies("MyCookie") = "hello"
Response.Cookies("MyCookie").Expires = Date + 365

f_sCookie = Request.Cookies("MyCookie")
Response.Write f_sCookie
%>

CountryHawk

Keywords: asp, CountryHawk, country
<%
Function CountryInfo_Get() ' As String
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Grabs user country info using CountryHawk.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim f_oCountryHawk
Dim f_sCountry

Set f_oCountryHawk = Server.CreateObject("cyScape.CountryObj")

f_sCountry = f_oCountryHawk.CountryCode

Select Case Ucase(f_sCountry)
Case "TH", "VI", "RO", "MA", "VN", "LB", "PH", "ID", "PK", "NG"
FraudCheck = " DISABLED"
m_sFraudText = "Credit card payment type " &_
"available for U.S. orders only."
m_sFraudRadio1 = ""
m_sFraudRadio2 = "CHECKED"
Case Else
FraudCheck = ""
m_sFraudText = ""
m_sFraudRadio1 = "CHECKED"
m_sFraudRadio2 = ""
End Select

CountryInfo_Get = f_sCountry

Set f_oCountryHawk = Nothing
End Function
%>

Data: Stored Procedure: DBInteraction

Keywords: asp, data, stored procedure, DBInteraction, M2W

SET

Function MemberOptionsSet(v_bKeepAttachments, v_bDelete_SentItems)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Sets Member Options in tbl_mem_MemberOptions.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 f_iMemberID = g_oIMDB.getcookie(Request("GUID"), "MemberID")
 
 ' Object
 Set f_oDBInteract = Server.CreateObject("DBINteraction.StoredProc")
 
 ' Method
 Call f_oDBInteract.Execute("MemberOptionsSet", f_iRet, f_iMemberID, _
 v_bKeepAttachments, v_bDelete_SentItems)
 If f_iRet <> 0 Then
  MemberOptionsSet = False
 Else
  MemberOptionsSet = True
 End If

 Set f_oDBInteract = Nothing
End Function


GET

Function MemberOptionsGet(v_bKeepAttachments, v_bDelete_SentItems)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Gets Member Options from tbl_mem_MemberOptions.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 f_iMemberID = g_oIMDB.getcookie(Request("GUID"), "MemberID")
 
 ' Object
 Set f_oDBInteract = Server.CreateObject("DBINteraction.StoredProc")

 ' Method
 Set f_oRst = f_oDBInteract.Execute("MemberOptionsGet", f_iRet, f_iMemberID)
 If f_iRet <> 0 Then
  MemberOptionsGet = False
 Else
  MemberOptionsGet = True
  v_bKeepAttachments =  f_oRst.fields("KeepAttachments")
  v_bDelete_SentItems =  f_oRst.fields("Delete_SentItems")
 End If
 
 Set f_oRst = Nothing
 Set f_oDBInteract = Nothing
End Function

Database: Access ODBC

Keywords: asp, Access, ODBC, connection string
<%
f_sConnString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\mydatabase.mdb;Uid=Admin;Pwd=111111;"
%>

Database: Command Object

Keywords: asp, database, command object
<%
Dim f_oCommand
Dim f_sConnString

Set f_oCommand = Server.CreateObject("ADODB.Command")
f_sConnString = "DSN=myDSN"

With f_oCommand
.ActiveConnection = f_sConnString
.CommandText = "usp_UpdatePrices"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter (@Type, adVarWChar, adParamInput, 12, strType)
.Parameters.Append .CreateParameter (@Max, adCurrency, adParamOutput)
.Execute lngRecs, , adExecuteNoRecords
End With

Set f_oCommand = Nothing
%>

Database: DSN

Keywords: asp, database, dsn
<%
Dim f_oConn
Dim f_sSQLString

Set f_oConn = Server.CreateObject("ADODB.Connection")
f_oConn.Open("myDSN")

f_sSQLString = "SELECT * FROM dotComFailures WHERE company = 'Pets.com'"
f_oConn.Execute(strSQL)

f_oConn.Close
Set f_oConn = Nothing
%>

Database: DSN-less

Keywords: asp, dsn-less, connection string

<%
Dim f_oConn
Dim f_sConnString
Dim f_sSQLString

Set f_oConn = Server.CreateObject("ADODB.Connection")
f_sConnString = "Driver={Microsoft Access Driver (*.mdb)}; dbq=e:\websites\admin\store.mdb"
f_oConn.Open(f_sConnString)

f_sSQLString = "INSERT INTO products (product_id, product_price) VALUES ('test002', 24.55)"
f_oConn.Execute(f_sSQLString)

f_oConn.Close
Set f_oConn = Nothing
%>

Database: Filter

Keywords: asp, database, filter, recordset
<%
Dim f_oRS
Dim f_sConnString
Dim f_sSQLString

Set f_oRS = Server.CreateObject("ADODB.Recordset")
f_sConnString = "DSN=myDSN"

f_sConnString = "SELECT * FROM products"
f_oRS.Open(f_sSQLString, f_sConnString, 3, 3)

f_oRS.Filter = "UnitPrice < $10.00"

Do While Not f_oRS.EOF
Response.Write(objRS("ProductID") & "<br>")
f_oRS.MoveNext
Loop

f_oRS.Filter = adFilterNone

f_oRS.Filter = "SupplierID = 10"

Do While Not f_oRS.EOF
Response.Write(f_oRS("CategoryID") & "<br>")
f_oRS.MoveNext
Loop

f_oRS.Close
Set f_oRS = Nothing
%>

Database: JET

Keywords: asp, database, JET
<%
f_sConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\mydatabase.mdb"
%>

Database: ODBC

Keywords: asp, database, ODBC, connection string
<%
f_sConnString = "Driver={SQL Server};Server=SQL01;Database=products;Uid=sa;Pwd=111111;"
%>

Database: Recordset

Keywords: asp, database, recordset, eof, MoveNext, DSN, ADODB

<%
Dim f_oConn
Dim f_oRS
Dim f_sSQLString

Set f_oConn = Server.CreateObject("ADODB.Connection")
f_oConn.Open("storeDSN")

f_sSQLString = "SELECT * FROM products"
Set f_oRS = f_oConn.Execute(f_sSQLString)

While Not f_oRS.EOF
Response.Write f_oRS("product_name") & "<br>"
f_oRS.MoveNext
Wend

f_oRS.Close
f_oConn.Close

Set f_oRS = Nothing
Set f_oConn = Nothing
%>

 

<%
Dim f_oRS
Dim f_sConnString
Dim f_sSQLString

Set f_oRS = Server.CreateObject("ADODB.Recordset")
strConnect = "DSN=myDSN"

f_sConnString = "SELECT * FROM products"
f_oRS.Open(f_sSQLString, f_sConnString)

f_oRS.Close

Set f_oRS = Nothing
%>

 

<%
Dim f_oConn
Dim f_oRS

Set f_oConn = Server.CreateObject("ADODB.Connection")
f_oConn.Open("myDSN")

Set f_oRS = Server.CreateObject("ADODB.RecordSet")
f_oRS.Open "products", f_oConn, 0, 1, 2

While Not f_oRS.EOF
Response.Write(f_oRS("product_name") & "<br>")
f_oRS.MoveNext
Wend

f_oRS.Close
f_oConn.Close

Set f_oRS = Nothing
Set f_oConn = Nothing
%>

Database: Row Color

Keywords: asp, database, row color, RecordCount
<table>
<%
Dim f_oRS
Dim f_iRecordCount : f_iRecordCount = 0

Do While Not f_oRS.EOF
If f_iRecordCount Mod 2 = 0 Then
%>
<tr>
<td><%= f_oRS("partnumber") %></td>
<td><%= f_oRS("manufacturer") %></td>
<td><%= f_oRS("category") %></td>
</tr>
<%
Else
%>
<tr bgcolor="#d0d0d0">
<td><%= f_oRS("partnumber") %></td>
<td><%= f_oRS("manufacturer") %></td>
<td><%= f_oRS("category") %></td>
</tr>
<%
End If

f_iRecordCount = f_iRecordCount + 1

f_oRS.MoveNext       
Loop
%>
</table>

Database: Transaction

Keywords: asp, objectcontext, Transaction, abort, commit
<%@ TRANSACTION = Required %>

<%
Dim f_sText : f_sText = Request.Form("Textbox")

If f_sText = "" Then
ObjectContext.SetAbort
Response.write("You did not enter the text")
Else
Response.write("Processing transaction...")
End If

Sub OnTransactionCommit()
Response.Write("Operation was successful")
End Sub

Sub OnTransactionAbort()
Response.Write("Operation was unsuccessful")
End Sub
%>

Date Time Format

Keywords: asp, date, time, FormatDateTime
<%
Date() '3/12/2001
Now() '3/12/2001 6:57:24 AM
Time() '6:57:24 AM

strDate = Now()
FormatDateTime(strDate, 0) '3/12/2001 6:57:24 AM
FormatDateTime(strDate, 1) 'Monday, March 12, 2001
FormatDateTime(strDate, 2) '3/12/2001
FormatDateTime(strDate, 3) '6:57:24 AM
FormatDateTime(strDate, 4) '06:57
FormatDateTime(Now(),vblongdate) 'Monday, March 12, 2001

Year(strDate) '2001
Month(strDate) '3
Day(strDate) '12
Day(strDate) & "/" & Month(strDate) & "/" & Year(strDate) '12/3/2001
MonthName(Month(strDate)) 'March
MonthName(Month(strDate), 1) 'Mar
WeekDay(strDate) '2
WeekDayName(WeekDay(strDate)) 'Monday
WeekDayName(WeekDay(strDate), 1) 'Mon
Minute(strDate) '57
Second(strDate) '24
%>

Date: Calcs

Keywords: asp, date, calculation, DateAdd, DateDiff
<%
strDate = Now() '3/12/2001 6:57:24 AM
DateAdd("d", 1, strDate) '3/13/2001 6:57:24 AM
DateAdd("d", -1, strDate) '3/11/2001 6:57:24 AM
DateDiff("d", "1/1/2000", strDate) '436
'(yyyy, q, m, y, d, w, ww, h, n, s)
%>

Dates: Format: DDMMYYYY

Keywords: asp 3.0, dates, format, ddmmyyyy

strDate = Date()


&START=" & FormatDate(strDate) 'mmddyyyyy

 

Function FormatDate(thedate)
 Dim myDay
 Dim myMonth
 Dim myYear

 myDay = Day(thedate)
 If Len(myDay)=1 Then myDay="0" & myDay

 myMonth = Month(thedate)
 If Len(myMonth)=1 Then myMonth="0" & myMonth

 myYear = Year(thedate)

 FormatDate = myMonth & myDay & myYear
End Function

eCommerce: Credit Card Test

Keywords: asp, eCommerce, credit card, test
'Visa
4111 1111 1111 1111

'Amex
370000000000002

'MC
5424000000000015

eCommerce: Credit Card Validate

Keywords: asp, eCommerce, credit card, validate
<%
Dim f_iCCNumber : f_iCCNumber = TRIM(Request("ccnumber"))
Dim f_dCCExpires : f_dCCExpires = TRIM(Request("ccexpires"))

If Not validCCNumber(f_iCCNumber) Then
Response.Write "Invalid Credit Card Number."
Else
Response.Write "Valid Credit Card Number."
End If

If Not isDATE(f_dCCExpires) Then
Response.Write "Invalid expiration date."
Else
Response.Write "Valid expiration date."
End If

Function validCCNumber(ccnumber)
ccnumber = CleanCCNum(ccnumber)
If ccnumber = "" Then
validCCNumber = False
Else
isEven = False
digits = ""  
    
For i = Len(ccnumber) To 1 Step -1
If isEven Then
digits = digits & CINT(MID(ccnumber, i, 1)) * 2
Else               
digits = digits & CINT(MID(ccnumber, i, 1))
End If
          
isEven = (Not isEven)
Next

checkSum = 0

For i = 1 To Len(digits) Step 1
checkSum = checkSum + CINT(MID(digits, i, 1 ))       
Next

validCCNumber = ((checkSum Mod 10) = 0)
End If
End Function

Function CleanCCNum(ccnumber)
For i = 1 To Len(ccnumber)
If isNumeric(MID(ccnumber, i, 1)) Then
CleanCCNum = CleanCCNum & MID(ccnumber, i, 1)
End If
Next
End Function
%>

eCommerce: Session Cart

Keywords: asp, eCommerce, session, cart, shopping cart, constant

<%
CONST CARTPID = 0
CONST CARTNAME = 1
CONST CARTPRICE = 2
CONST CARTQTY = 3

If Not isArray(Session("cart")) Then
Dim localCart(4, 10)
Else
localCart = Session("cart")
End If

m_iProductID = Request("ProductID")
m_sProductName = Request("ProductName")
m_cProductPrice = Request("ProductPrice")
m_iProductQty = Request("ProductQty")

For i = 0 To Ubound(localCart, 2)
If localCart(CARTPID, i) = "" Then
localCart(CARTPID, i) = m_iProductID
localCart(CARTNAME, i) = m_sProductName
localCart(CARTPRICE, i) = m_cProductPrice
localCart(CARTQTY, i) = m_iProductQty
Exit For
End IF
Next

For i = 0 To Ubound(localCart, 2)
If localCart(CARTPID, i) <> "" Then
Response.Write localCart(CARTPID, i) & "<br>"
Response.Write localCart(CARTNAME, i) & "<br>"
Response.Write localCart(CARTPRICE, i) & "<br>"
Response.Write localCart(CARTQTY, i) & "<br><br>"
End If
Next

Session("cart") = localCart
%> 

eCommerce: Shipping

Keywords: asp, eCommerce, shipping
'UPS
OLD: http://wwwapps.ups.com/tracking/tracking.cgi?TrackNum=" & Trim(RS("tracking"))
NEW: http://wwwapps.ups.com/WebTracking/processInputRequest?TypeOfInquiryNumber=
T&AgreeToTermsAndConditions=yes&InquiryNumber1=

'FedEx
"http://www.fedex.com/us/tracking/"

'Priority/Express
"http://www.usps.com/cttgate"

Email: CDO

Keywords: asp, email, cdo
<%
Set f_oMail = Server.CreateObject("CDO.Message")

With f_oMail
.To = "test@test.com"
.From = Request.Form("email_from")
.Subject = "E-Mail Test"
.HtmlBody = Request.Form("email_body")
.Send
End With

Set f_oMail = Nothing
%>

Email: CDO Config

Keywords: asp, email, cdo, config
<%
<!-- METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library" -->
<!-- METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4"
NAME="ADODB Type Library" -->

Dim f_oCDO
Dim f_oConfig

Set f_oCDO = Server.CreateObject("CDO.MESSAGE")
Set f_oConfig = CreateObject("CDO.Configuration")

f_oConfig.Fields(cdoSendUsingMethod) = 2 
f_oConfig.Fields(cdoSMTPServer) = "mail.domain.com"
f_oConfig.Fields(cdoSMTPServerPort) = 25 
f_oConfig.Fields(cdoSMTPAuthenticate) = cdoBasic  

f_oConfig.Fields.Update
Set f_oCDO.Configuration = f_oConfig

If IsObject(f_oCDO) Then
With f_oCDO
.To = "test@yahoo.com"
.From = "test@hotmail.com"
.Subject = "Test 123"
.HTMLBody = "This is a test."
.Send
End With
Else
Response.Write("no object")
End If

Set f_oCDO = Nothing
Set f_oConfig = Nothing
%>

Email: CDO Constants

Keywords: asp, email, cdo, constants
<%
' CDONTS Attachment.Type values
Const CdoFileData = 1
Const CdoEmbeddedMessage = 4

' CDONTS Message.Importance Values.  Also used in NewMail.Importance
Const CdoLow = 0
Const CdoNormal = 1
Const CdoHigh = 2

' CDONTS Message.MessageFormat and Session.MessageFormat Values
Const CdoMime = 0
Const CdoText = 1

' CDONTS NewMail.AttachFile and NewMail.AttachURL EncodingMethod Values
Const CdoEncodingUUencode = 0
Const CdoEncodingBase64 = 1

' CDONTS NewMail.BodyFormat Values
Const CdoBodyFormatHTML = 0
Const CdoBodyFormatText = 1

' CDONTS NewMail.MailFormat Values
Const CdoMailFormatMime = 0
Const CdoMailFormatText = 1

' CDONTS Recipient.Type Values
Const CdoTo = 1
Const CdoCc = 2
Const CdoBcc = 3

' CDONTS Session.GetDefaultFolder Values
Const CdoDefaultFolderInbox = 1
Const CdoDefaultFolderOutbox = 2
%>

Email: CDONTS

Keywords: asp, email, CDONTS
<%
Set f_oMail = Server.CreateObject("CDONTS.NewMail")

With f_oMail
.From = Request.Form("email_from")
.To = "test@test.com"
.CC = "test@test.com"
.Subject = "E-Mail Test"
.MailFormat = 0
.BodyFormat = 0
.Body = Request.Form("email_body")
.Send
End With

Set f_oMail = Nothing
%>

Email: JMail

Keywords: asp, email, jmail
<%
Set f_oJMail = Server.CreateObject("JMail.smtpmail")

With f_oJMail
.ServerAddress = "mail.test.com:25"
.Sender = Request.Form("email_from") 
.Subject = "Feedback"
.AddRecipient = "info@test.com"
.Body = "need info"
.Execute
End With

Set f_oJMail = Nothing
%>

Error Object

Keywords: asp, error object
<%
For Each objErr In f_oConn.Error
Response.Write("<p>")
Response.Write("Description: ")
Response.Write(objErr.Description & "<br/>")
Response.Write("</p>")
Next
%>

Error Object: GetLastError

Keywords: asp, error object, GetLastError
<%
Dim objErrorInfo
Set objErrorInfo = Server.GetLastError

Response.Write("ASPCode = " & objErrorInfo.ASPCode)
Response.Write("ASPDescription = " & objErrorInfo.ASPDescription)
Response.Write("Category = " & objErrorInfo.Category)
Response.Write("Column = " & objErrorInfo.Column)
Response.Write("Description = " & objErrorInfo.Description)
Response.Write("File = " & objErrorInfo.File)
Response.Write("Line = " & objErrorInfo.Line)
Response.Write("Number = " & objErrorInfo.Number)
Response.Write("Source = " & objErrorInfo.Source)
%>

Error: Response Buffer Limit Exceeded

Keywords: asp, error, Response Buffer Limit Exceeded

The reason this is happening is because buffering is turned on by default, and IIS 6 cannot handle the large response.

 

In Classic ASP, at the top of your page, after <%@Language="VBScript"%> add:
<%Response.Buffer = False%>

 

In ASP.NET, you would add Buffer="False" to your Page directive.
For example:
<%@Page Language="C#" Buffer="False"%>

Fields Count

Keywords: asp, fields, count
<%
Response.Write("<br>" & f_oRS.Fields.Count & "<br>")
%>

Fields Names

Keywords: asp, field, names
<%
For i = 0 To f_oRS.Fields.Count - 1
Response.Write f_oRS.Fields(i).Name
Next
%>

File: Create

Keywords: asp, file, create, FileSystemObject
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")
set f_oTextFile = f_oFile.CreateTextFile("e:\websites\test\test.txt")

f_oTextFile.WriteLine("Hello")

f_oTextFile.Close
Set f_oFile = Nothing
%>

File: Include

Keywords: asp, include file, virtual
<%
<!-- #include file="functions.inc" -->

<!-- #include virtual="/inc/functions.inc" -->
%>

File: List

Keywords: asp, file, list, FileSystemObject
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")
Set f_oFolder = f_oFile.GetFolder("e:\websites\test\asp")

For Each f_oFile In f_oFolder.Files
Response.Write f_oFile.Name & "<br>"
Next

Set f_oFile = Nothing
Set f_oFolder = Nothing
%>

File: Modify

Keywords: asp, file, modify, FileSystemObject
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")

If f_oFile.FileExists("e:\websites\test\test.txt") Then
Set f_oTextFile = f_oFile.OpenTextFile("e:\websites\test\test.txt")

f_oTextFile.WriteBlankLines(2)
f_oTextFile.WriteLine("Hello again")

f_oTextFile.Close
End If

Set f_oFile = Nothing
%>

File: Move

Keywords: asp, file, move, FileSystemObject
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")

If f_oFile.FileExists("e:\test\test.asp") Then
f_oFile.MoveFile "e:\test\test.asp", "e:\test\move\test_copy.asp"
End If

Set f_oFile = Nothing
%>

File: Read

Keywords: asp, file, read, FileSystemObject
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")
Set f_oTextFile = f_oFile.OpenTextFile("e:\websites\counter.txt")

While Not f_oTextFile.AtEndOfStream
Response.Write f_oTextFile.ReadLine
Wend

f_oTextFile.Close
Set f_oFile = Nothing
%>

GUID

Keywords: asp, GUID, randomize
<%
Function GetGUID()
' Returns a GUID (globally unique identifier), 16 byte hexadecimal
' Example GetGUID = 494F1BF1-B507-9F72-BEBC-289A189FD2B3

Dim f_sTmp, f_Char
Dim f_iRnd, i

Randomize()
For i = 1 To 32
f_iRnd = Int(Rnd * 100) Mod 16
If f_iRnd > 9 Then
Select Case f_iRnd
Case 10
f_Char = "A"
Case 11
f_Char = "B"
Case 12
f_Char = "C"
Case 13
f_Char = "D"
Case 14
f_Char = "E"
Case 15
f_Char = "F"
End Select
Else
f_Char = Left(f_iRnd, 1)
End If
f_sTmp = f_sTmp & f_Char
Next

GetGUID = Left(f_sTmp, 8) & "-" & Mid(f_sTmp, 9, 4) & "-" & Mid(f_sTmp, 13, 4) &
"-" & Mid(f_sTmp, 17, 4) & "-" & Mid(f_sTmp, 21, 12)
End Function
%>

Hit Counter

Keywords: asp, hit counter
<%
Sub HitCounter_Set()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Increments the site hit counter.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim f_oFile
Dim f_sFilePath
Dim f_oReadFile
Dim f_iHits
Dim f_oWriteFile

Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")
f_sFilePath = Server.MapPath("mcv_counter.txt")

' Open file
Set f_oReadFile = f_oFile.OpenTextFile(f_sFilePath, 1, True)

' Read file (hits)
If Not f_oReadFile.AtEndOfStream Then
f_iHits = Trim(f_oReadFile.ReadLine)
If f_iHits = "" Then f_iHits = 0
Else
f_iHits = 0
End If

f_oReadFile.Close
Set f_oReadFile = Nothing

f_iHits = f_iHits + 1

' Write file
Set f_oWriteFile = f_oFile.CreateTextFile(f_sFilePath, True)
f_oWriteFile.WriteLine(f_iHits)
f_oWriteFile.Close
Set f_oWriteFile = Nothing

Set f_oFile = Nothing
End Sub
%>

IIF

Keywords: asp, IIF, immediate if
<%
Dim f_bRet : f_bRet = False
Dim f_iNumber : f_iNumber = 2

f_bRet = IIf(f_iNumber = 2, True, False)

Response.Write(f_bRet)

Public Function IIf(blnExpression, vTrueResult, vFalseResult)
If blnExpression Then
IIf = vTrueResult
Else
IIf = vFalseResult
End If
End Function
%>

No Cache

Keywords: asp, no cache, CacheControl
<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache" 
Response.Expires = -1
%>

Randomize

Keywords: asp, randomize
<%
Randomize()
Response.Write Rnd
%>

Request Object

Keywords: asp, request, REMOTE_ADDR, Request.Form

<%
Dim f_sCompanyName : f_sCompanyName = Request.Form("CompanyName")

Dim f_sCompanyPhone : f_sCompanyPhone = Request.Querystring("CompanyPhone")

Dim f_sUserName : f_sUserName = Request.Cookies("UserName")

Dim f_sIPAddress : f_sIPAddress = Request.ServerVariables("REMOTE_ADDR")
%>

 

<%
If Request.Form.Count <> 0 Then
Response.Write "Form submitted"
End If
%>

 

<%
' Grab All
Sub ReadFormVariables()
For Each Field In Request.Form
    TheString = Field & " = " & Request.Form("" & Field & "")
    Execute(TheString)
Next
End Sub
%>

Response Object

Keywords: asp, response object
<%
Response.Cookies("UserName") = "cjanco"

Response.Write("Hello")

Response.Buffer = True

Response.Expires = 0

Response.ExpiresAbsolute = #December 3, 1998#
%>

ScriptEngine

Keywords: asp, ScriptEngine, version
<%= ScriptEngine %>
<%= ScriptEngineMajorVersion %>
<%= ScriptEngineMinorVersion %>

Select/Dropdown: Database: Selected

Keywords: asp, select, dropdown, selected, database

<%
Function Selected(val1, val2)
If Cstr(val1) = Cstr(val2) Then
Selected = "SELECTED"
Else
Selected = ""
End If
End Function
%>

 

<select name="color">
<option value="red" <%= Selected(v_sColor, "red") %>>Red</option>
<option value="green" <%= Selected(v_sColor, "green") %>>Green</option>
<option value="blue" <%= Selected(v_sColor, "blue") %>>Blue</option>
</select>

Server Object

Keywords: asp, server object, HTMLEncode, CreateObject, ServerVariables
<%
Set f_oFile = Server.CreateObject("Scripting.FileSystemObject")

Server.Execute("myfile.asp")

Server.Transfer("myfile.asp")

Response.Write Server.MapPath(Request.ServerVariables("PATH_INFO"))

Response.Write Server.HTMLEncode(rs.Fields("my_field"))

Dim aValue : aValue = "red & green"
Dim f_sPath : f_sPath = "my.asp?a=" & Server.URLEncode(aValue)
%>

Server Variables

Keywords: asp, HTTP_REFERER, REMOTE_ADDR, LOCAL_ADDR, HTTP_HOST, IP address

<%
f_sReferer = Request.ServerVariables("HTTP_REFERER")
f_sPhysicalPath = Request.ServerVariables("APPL_PHYSICAL_PATH") E:\websites\test\
f_sPath = Request.ServerVariables("PATH_TRANSLATED") E:\websites\test\test.asp
f_sHost = Request.ServerVariables("HTTP_HOST") www.charlesjanco.com
f_sIPLocal = Request.ServerVariables("LOCAL_ADDR")
f_sIPRemote = Request.ServerVariables("REMOTE_ADDR")

For Each TheStuff In Request.ServerVariables
   Response.Write TheStuff & ": " _
      & Request.Servervariables(TheStuff) & "<br>"
Next
%>

Session Array

Keywords: asp, session, array
<%
Dim Customer(3)
Customer(0) = Request.Form("firstName")
Customer(1) = Request.Form("lastName")

Session("Customer") = Customer

' Add to Array later
Customer = Session("Customer")
Customer(2) = Request.Form("address")
Customer(3) = Request.Form("city")
Session("Customer") = Customer

Response.Write Session("Customer")(0)
%>

Session Object

Keywords: asp, session object, timeout, SessionId
<%
Session.Timeout = 30

Dim f_sUser : f_sUser = Session("User")

Response.Write(Session.SessionID)

' German
Session.CodePage = 1252

' French Francs
Session.LCID = 1036
%>

String: InStr

Keywords: asp, string, InStr
<%
f_sUrl = "www.theonion.com"

If InStr(f_sUrl, "www") <> 0 Then
Response.Write "True"
End If
%>

String: Len

Keywords: asp, string, len, length
<%
f_sEmail = Trim(Request.Form("email"))

f_iCharCount = Len(f_sEmail)

If f_iCharCount >= 25 Then
f_sEmail = Left(f_sEmail, 25) & "..."
End If

Response.Write f_sEmail
%>

String: Position

Keywords: asp, string, position, left, right, middle
<%
f_sName = "Cherokee"

'Left
f_sName = Left(f_sName, 2)
'(Ch)

'Right
f_sName = Right(f_sName, 3)
'(kee)

'Middle
f_sName = Right(f_sName, 3, 3)
'(ero)
%>

String: Regular Expression

Keywords: asp, regular expression, RegExp, pattern

<%
'Test Method
f_sString = "Here is a link www.link.com"

Set f_oRegExpr = New RegExp

With f_oRegExpr
.Pattern = ".com"
.Global = True
.IgnoreCase = True
End With

f_sExpressionMatch = f_oRegExpr.Test(f_sString)

If f_sExpressionMatch Then
Response.Write(f_oRegExpr.Pattern & " was found")
Else
Response.Write(f_oRegExpr.Pattern & " was not found")
End If

Set f_oRegExpr = Nothing
%>

String: Regular Expression: Email

Keywords: asp, string, regular expression, validation, email, RegExp
<%
Function RegExp_Email(sEmail) ' As boolean
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Validate email address.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
RegExp_Email = False

Dim f_oRegEx
Dim f_bRet

Set f_oRegEx = New RegExp

f_oRegEx.Pattern = "^[\w-\.]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,3}$"

f_oRegEx.IgnoreCase = True

f_bRet = f_oRegEx.Test(sEmail)

If Not f_bRet Then
Exit Function
End If

RegExp_Email = True
End Function

f_bRet = RegExp_Email(Cstr(m_sToEmail))
If f_bRet <> True Then
m_sError = "Please enter a valid 'To' address."
Else
Call Message_Send()
End If
%>

String: Regular Expression: Match

Keywords: asp, string, regular expression, pattern
<%
' Execute method
f_sString = "This website contains lots of information about" &_
"ASP, asp, as well as Asp."

Set f_oRegExpr = New RegExp

With f_oRegExpr
.Pattern = "ASP"
.IgnoreCase = False
.Global = True
End With

Set f_sExpressionMatch = f_oRegExpr.Execute(f_sString)

If f_sExpressionMatch.Count > 0 Then
For Each matched in f_sExpressionMatch
Response.Write(matched.Value & " matched at position " & matched.FirstIndex)
Next
Else
Response.Write(f_oRegExpr.Pattern & " was not found in the string: " & f_sString)
End If

Set f_oRegExpr = Nothing
%>

String: Replace

Keywords: asp, string, replace, fix quotes
<%
'Line Breaks
f_sMemo = Request.Form("memo")
f_sMemo = Replace(f_sMemo, chr(13), "<br>")

f_sMemo = Replace(f_sMemo, vbLf, " ")

f_sMemo = Replace(f_sMemo, vbCr, " ")

'Tabs
f_sMemo = Replace(f_sMemo, vbTab, " ")

'Single Quotes
f_sMemo = Replace(f_sMemo, "'", "'")

'Single Quotes
Function FixQuotes(theString)
FixQuotes = Replace(theString, "'", "''")
End Function
%>

Submit Loop

Keywords: asp, submit, loop

<%

'Loop through entered values.


v_sAction = Request.Form("action")

If Ucase(v_sAction) = "GO" Then Call MyFunction()

Function MyFunction()
For iNameServer = 1 To 4
If Request.Form( "name_server" & iNameServer ) <> "" Then
Response.Write iNameServer & Request.Form( "name_server" & iNameServer )
End If
Next
End Function
%>

<form action="test.asp" method="post" name="form1">
<input type="text" size="20" name="name_server1">
<input type="text" size="20" name="name_server2">
<input type="text" size="20" name="name_server3">
<input type="text" size="20" name="name_server4">
<input type="hidden" name="action" value="go">
<input type="submit" value="click">
</form>

Type Library

Keywords: asp, type library, COM, TypeLib

A Type Library is a container for the contents of a DLL file corresponding to a COM object. By including a call to the TypeLibrary in the Global.asa file, the constants of the COM object can be accessed, and errors can be better reported by the ASP code. If your Web application relies on COM objects that have declared data types in type libraries, you can declare the type libraries in Global.asa.

 

<!-- METADATA TYPE="TypeLib" file="filename" uuid="typelibraryuuid" version="versionnumber" lcid="localeid" -->

Wait Page

Keywords: asp, wait page
<script language="JavaScript">
<!--
// wait screen
if(document.layers) 
{
	var ns4 = true;
}
if(document.all) 
{
	var ie4 = true;
}

function showObject(obj) 
{
	if (ns4) obj.visibility = "show";
	else if (ie4) obj.visibility = "visible";
}
function hideObject(obj) 
{
	if (ns4) 
	{
		obj.visibility = "hide";
	}
	if (ie4) 
	{
		obj.visibility = "hidden";
	}
}
// -->
</script>

<div id="splashScreen" style="position:absolute;z-index:5;top:30%;left:35%;">
	<table bgcolor="#000000" border="1" bordercolor="#E0E4F1" height="200" width="300">
		<tr>
			<td width"=100%" height="100%" bgcolor="#ffffff" align="center" valign="middle">
				<font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px" color="#336699">
				<br><br>
				<b>Order processing.  Please wait...</b>
				<br><br>
				<img src="../images/icons/wait.gif" border="1" width="75" height="15">
				<br><br>
				</font>
			</td>
		</tr>
	</table>
</div>

<% Response.Flush %>

' All processing and content here...

<script language="JavaScript">
<!--
if(ns4) 
{
	var splash = document.splashScreen;
}
else if(ie4) 
{
	var splash = document.all.splashScreen.style;
}
hideObject(splash);
// -->
</script>