|
|
|
| ASP : Array |
| Display Contents |
<%
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
%>
|
| Count Elements |
<%
If IsArray(f_aArr) = False Then
f_iVar = 0
Else
f_iVar = (UBound(f_aArr) - LBound(f_aArr)) + 1
End If
%>
|
| Check if Empty |
<%
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
%>
|
| 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, " ")
%>
|
| Word Count |
<%
Function GetWordCount(var)
GetWordCount = UBound(Split(var, " ", -1, 1)) + 1
End Function
%>
|
| Jump to Top |
| ASP : Class |
<%
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
%>
|
| Jump to Top |
| ASP : Command |
<%
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
%>
|
| Jump to Top |
| ASP : Connect |
| Access ODBC |
<%
f_sConnString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\mydatabase.mdb;Uid=Admin;Pwd=111111;"
%>
|
| JET |
<%
f_sConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\mydatabase.mdb"
%>
|
| SQL ODBC |
<%
f_sConnString = "Driver={SQL Server};Server=SQL01;Database=products;Uid=sa;Pwd=111111;"
%>
|
| Error |
<%
For Each objErr In f_oConn.Error
Response.Write("<p>")
Response.Write("Description: ")
Response.Write(objErr.Description & "<br/>")
Response.Write("</p>")
Next
%>
|
| Jump to Top |
| ASP : Cookies |
<%
Response.Cookies("MyCookie") = "hello"
Response.Cookies("MyCookie").Expires = Date + 365
f_sCookie = Request.Cookies("MyCookie")
Response.Write f_sCookie
%>
|
<%
For Each cookie In Request.Cookies
Response.Write "<b>" & cookie & ": </b> " & Request.Cookies(cookie) & "<br>"
Next
%>
|
| Jump to Top |
| ASP : DateTime |
| Format |
<%
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
%>
|
| Calculation |
<%
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)
%>
|
| Jump to Top |
| ASP : 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
%>
|
| Jump to Top |
| ASP : DSN-Less |
<%
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
%>
|
| Jump to Top |
| ASP : eCommerce |
| Session Cart |
<%
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
%>
|
| 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"
|
| Valid Credit Card |
<%
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
%>
|
'Visa
4111 1111 1111 1111
'Amex
370000000000002
'MC
5424000000000015
|
| Jump to Top |
| 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
%>
|
| CDO (WIN 2000) |
<%
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
%>
|
| CDO (WIN 2000) - 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 = "cj@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
%>
|
| 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
%>
|
| 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
%>
|
| Jump to Top |
| ASP : Fields |
| Count |
<%
Response.Write("<br>" & f_oRS.Fields.Count & "<br>")
%>
|
| Field Names |
<%
For i = 0 To f_oRS.Fields.Count - 1
Response.Write f_oRS.Fields(i).Name
Next
%>
|
| Jump to Top |
| ASP : Files |
| 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
%>
|
| Create |
<%
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
%>
|
| Include |
<%
<!-- #include file="functions.inc" -->
<!-- #include virtual="/inc/functions.inc" -->
%>
|
| List |
<%
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
%>
|
| Modify |
<%
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
%>
|
| Move |
<%
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
%>
|
| Read |
<%
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
%>
|
| Jump to Top |
| ASP : Filter |
<%
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
%>
|
| Jump to Top |
| ASP : Form |
| Remove space after form tag. |
<style type="text/css">
<!--
form {margin-bottom : 0;}
//-->
</style>
|
| Jump to Top |
| ASP : Functions |
| InStr |
<%
f_sUrl = "www.theonion.com"
If InStr(f_sUrl, "www") <> 0 Then
Response.Write "True"
End If
%>
|
| Len |
<%
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
%>
|
| Position |
<%
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)
%>
|
| Replace |
<%
'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
%>
|
| Randomize |
<%
Randomize()
Response.Write Rnd
%>
|
| Jump to Top |
| ASP : GUID |
<%
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
%>
|
| Jump to Top |
| ASP : IIF |
| Create IIF in VBScript |
<%
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
%>
|
| Jump to Top |
| ASP : Objects |
| AdRotator |
'(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 |
<%
Dim f_sCompanyName : f_sCompanyName = Application("CompanyName")
%>
|
| ASPError |
<%
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)
%>
|
| ASPHTTP |
<%
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
%>
|
| ObjectContext |
<%@ 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
%>
|
| RegExp |
<%
'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
%>
|
<%
' 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
%>
|
<%
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
%>
|
| Request |
<%
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 |
<%
Response.Cookies("UserName") = "cjanco"
Response.Write("Hello")
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = #December 3, 1998#
%>
|
| Server |
<%
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)
%>
|
| Session |
<%
Session.Timeout = 30
Dim f_sUser : f_sUser = Session("User")
Response.Write(Session.SessionID)
' German
Session.CodePage = 1252
' French Francs
Session.LCID = 1036
%>
|
<%
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)
%>
|
| Jump to Top |
| ASP : Recordset |
<%
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
%>
|
| Jump to Top |
| ASP : Row Color |
<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>
|
| Jump to Top |
| ASP : Selected |
| Code |
<%
Function Selected(val1, val2)
If Cstr(val1) = Cstr(val2) Then
Selected = "SELECTED"
Else
Selected = ""
End If
End Function
%>
|
| HTML |
<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>
|
| Jump to Top |
| ASP : Submit |
| 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>
|
| Jump to Top |
| ASP : Transaction |
<%@ Transaction = Required %>
<%
' ObjectContext.SetComplete
Sub OnTransactionCommit()
Response.Write "Transaction comitted"
End Sub
' ObjectContext.SetAbort
Sub OnTransactionAbort()
Response.Redirect(error_page.asp?ErrorID=607)
End Sub
%>
|
| Jump to Top |
| ASP : 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" -->
|
| Jump to Top |
| ASP : User Info |
| BrowsCap |
<%
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
%>
|
| BrowserHawk |
<%
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
%>
|
| BrowserHawk |
<%
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
%>
|
| Script Engine |
<%= ScriptEngine %>
<%= ScriptEngineMajorVersion %>
<%= ScriptEngineMinorVersion %>
|
| Server Variables |
<%
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
%>
|
| Jump to Top |
| 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>
|
| Jump to Top |
|
|