Script

Filter
2001-08-29

Webläsaranpassning

Asp
Anpassa bredden på textarea i formulär
<% if instr(request.servervariables("HTTP_USER_AGENT"), "MSIE") then %>
    <textarea cols="80" rows="10" wrap="virtual" name="message">
    <%= server.HTMLEncode(rs("message")) %>
    </textarea>
<% else %>
    <textarea cols="40" rows="10" wrap="virtual" name="message">
    <%= server.HTMLEncode(rs("message")) %>
    </textarea>
<% end if %>
2001-08-24

Debug hjälpmedel

Asp
Ett enkelt script för att slippa skriva response.write för att kolla ett värde vid utveckling
<%
Function debug(str)
    If Request.ServerVariables("REMOTE_ADDR") = "127.0.0.1" or _
        Session("developer") = True Then
        Response.Write str & "<br>" & vbCrLf
    End If
End Function
%>
2001-08-23

Email with CDONTS

Asp
Have you ever needed to send email from a web page? Perhaps to build a "Send this to a Friend" link? Have no fear, CDONTS is here. You can easily send email (and attachments!) with the Collaboration Data Objects for NT server. Note that this requires SMTP
Set objMail = Server.CreateObject("CDONTS.NewMail")

objMail.From = Request.Form("From")
objMail.To = Request.Form("To")
objMail.CC = Request.Form("CC")
objMail.BCC = Request.Form("BCC")
objMail.Subject = Request.Form("Subject")

msgBody = "Dear Friend, this email is coming to you from CDONTS!"

objMail.Body = msgBody
objMail.Send
Set objMail = nothing
2001-08-23

Datumavgränsare för databasen

Asp
Determine, from an existing connection, what datedelimiter you should use. This function checks for Access and if it finds it sets the delimiter to #. If it doesn't it defaults to ' for SQL Server.
<%
' This function takes an open ADODB.Connection object and will
' return the appropriate date delimiter to be used for queries.
' Only Access is checked for... ' is returned o/w. (SQL Server)
Function DateDelimiter(ByRef cnnOpenConnectionObject) ' As String
    Dim strDBMSName
    Dim strDateDelimiter

    strDateDelimiter = "'"

    strDBMSName = cnnOpenConnectionObject.Properties("DBMS Name").Value

    If InStr(1, strDBMSName, "access", 1) Then strDateDelimiter = "#"
    If InStr(1, strDBMSName, "jet", 1) Then strDateDelimiter = "#"

    DateDelimiter = strDateDelimiter
End Function
%>
This allows you to write code like this that will run against either database without any changes. 
<%
' Assuming there's an open connection named cnnOpenConnection,
' the following will produce the appropriate SQL query for
' either Access or SQL Server without any code changes!
Dim strDD
Dim strSQL

strDD = DateDelimiter(cnnOpenConnection)

strSQL = "SELECT * FROM table_name " & _
    "WHERE date_field < " & strDD & Now() & strDD & ";"
%>
2001-07-12

Anslutningssträngar till Access

Asp
Ett par varianter (alt 1 för äldre servrar)
Anslutningssträngar till Access:

' Skapa ett connectionobjekt:
set conn = server.createObject("ADODB.Connection")

'Alt 1:
conn.open ("driver={Microsoft Access Driver (*.mdb)};dbq=C:\sokvag\databas.mdb")

'Alt 2:
'conn.open ("provider=Microsoft.Jet.OLEDB.4.0; data source=C:\sokvag\databas.mdb")
🙂