Examples of ASP techniques: procedures for working with forms

Source: Internet
Author: User
Tags add chr count end mail trim

The following are the referenced contents:

Inserting Form content into the Database with ASP.

<%
'--loader.asp--
'--Version 1.5.2
'--Last updated 12/5/2002
'
' Faisal Khan
' Faisal@stardeveloper.com
' Www.stardeveloper.com
' Class for handling binary uploads

Class Loader
Private Dict

Private Sub Class_Initialize
Set dict = Server.CreateObject ("Scripting.Dictionary")
End Sub

Private Sub Class_Terminate
If IsObject (intdict) Then
Intdict.removeall
Set intdict = Nothing
End If
If IsObject (dict) Then
Dict. RemoveAll
Set dict = Nothing
End If
End Sub

Public Property Get Count
Count = Dict. Count
End Property

Public Sub Initialize
If request.totalbytes > 0 Then
Dim Bindata
Bindata = Request.BinaryRead (request.totalbytes)
GetData Bindata
End If
End Sub

Public Function Getfiledata (name)
If Dict. Exists (name) Then
Getfiledata = dict (name). Item ("Value")
Else
Getfiledata = ""
End If
End Function

Public Function GetValue (name)
Dim GV
If Dict. Exists (name) Then
GV = CSTR (dict (name). Item ("Value"))

GV = Left (Gv,len (GV)-2)
GetValue = GV
Else
GetValue = ""
End If
End Function

Public Function savetofile (name, path)
If Dict. Exists (name) Then
Dim Temp
temp = dict (name). Item ("Value")
Dim FSO
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Dim file
Set file = fso. CreateTextFile (PATH)
For tpoint = 1 to LenB (temp)
File. Write Chr (AscB (MidB (temp,tpoint,1))
Next
File. Close
SaveToFile = True
Else
SaveToFile = False
End If
End Function

    public Function getfilename (name)
      If Dict. Exists (name) Then
        Dim temp, Temppos
           temp = dict (name). Item ("FileName")
          temppos = 1 + instrrev (temp, "\")
          GetFileName = Mid (temp, temppos)
       Else
        getfilename = "
      End If
    end Function

    public Function GetFilePath (name)
      If Dict. Exists (name) Then
        Dim temp, Temppos
           temp = dict (name). Item ("FileName")
          temppos = InStrRev (temp, "\")
           GetFilePath = Mid (temp, 1, temppos)
       Else
        getfilepath = "
      end If
    End Function

Public Function Getfilepathcomplete (name)
If Dict. Exists (name) Then
Getfilepathcomplete = dict (name). Item ("FileName")
Else
Getfilepathcomplete = ""
End If
End Function

Public Function GetFileSize (name)
If Dict. Exists (name) Then
GetFileSize = LenB (dict (name). Item ("Value"))
Else
GetFileSize = 0
End If
End Function

    public Function getfilesizetranslated (name)
      If Dict. Exists (name) Then
        temp = LenB (dict (name). Item ("Value"))
          If temp <= 1024 Then
             getfilesizetranslated = temp & "bytes"  
           Else
             temp = FormatNumber ((temp/1024), 2)
             getfilesizetranslated = temp & "kilobytes"
          end If
      Else
        getfilesizetranslated = ""
      End If
    end Function

Public Function getContentType (name)
If Dict. Exists (name) Then
getContentType = dict (name). Item ("ContentType")
Else
getContentType = ""
End If
End Function

Private Sub GetData (rawdata)
Dim Separator
Separator = MidB (rawdata, 1, InstrB (1, RawData, ChrB (13))-1)

Dim Lenseparator
Lenseparator = LenB (separator)

Dim Currentpos
Currentpos = 1
Dim Instrbyte
Instrbyte = 1
Dim value, Mvalue
Dim Tempvalue
Tempvalue = ""

While Instrbyte > 0
Instrbyte = InStrB (Currentpos, rawdata, separator)
Mvalue = Instrbyte-currentpos

If mvalue > 1 Then
Value = MidB (RawData, Currentpos, Mvalue)

Dim Begpos, Endpos, Midvalue, Nvalue
Dim intdict
Set intdict = Server.CreateObject ("Scripting.Dictionary")

Begpos = 1 + InStrB (1, Value, ChrB (34))
Endpos = InStrB (Begpos + 1, value, ChrB (34))
Nvalue = Endpos

Dim Namen
Namen = MidB (value, Begpos, Endpos-begpos)

Dim Namevalue, IsValid
IsValid = True

If InStrB (1, Value, Stringtobyte ("Content-type")) > 1 Then

Begpos = 1 + InStrB (endpos + 1, value, ChrB (34))
Endpos = InStrB (Begpos + 1, value, ChrB (34))

If endpos = 0 Then
Endpos = Begpos + 1
IsValid = False
End If

Midvalue = MidB (value, Begpos, Endpos-begpos)
Intdict.add "FileName", Trim (bytetostring (midvalue))

Begpos = + InStrB (endpos + 1, value, Stringtobyte ("Content-type:"))
Endpos = InStrB (Begpos, Value, ChrB (13))

Midvalue = MidB (value, Begpos, Endpos-begpos)
Intdict.add "ContentType", Trim (bytetostring (midvalue))

Begpos = Endpos + 4
Endpos = LenB (value)

Namevalue = MidB (Value, Begpos, ((Endpos-begpos)-1))
Else
Namevalue = Trim (bytetostring (MidB (value, Nvalue + 5))
End If

If isValid = True Then

Intdict.add "Value", Namevalue
Intdict.add "Name", Namen

Dict. ADD bytetostring (Namen), intdict
End If
End If

Currentpos = Lenseparator + instrbyte
Wend
End Sub

End Class

Private Function stringtobyte (TOCONV)
Dim Tempchar
For i = 1 to Len (TOCONV)
Tempchar = Mid (Toconv, I, 1)
Stringtobyte = stringtobyte & ChrB (AscB (Tempchar))
Next
End Function

Private Function bytetostring (TOCONV)
For i = 1 to LenB (TOCONV)
bytetostring = bytetostring & Chr (AscB (MidB (toconv,i,1))
Next
End Function
%>

1. User interface:
<script language= "JavaScript" >
function Checkall (form)
{for (Var i=0;i<form.elements.length;i++)
{var e = form.elements[i];
if (e.name!= ' Chkall ')
e.checked = form.chkall.checked;
}
}
</script>


<body>
<form method= "POST" action= "del.asp" Name= "Form1" >
<table>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>
<tr>
&LT;TD ><input type= "checkbox" value= "Name=" > E-mail tradename
</tr>

<tr>
&LT;TD bgcolor= "#F1FBFC" height= "colspan=" 2 ">
<p align= "left" ><input type= "checkbox" Name= "Chkall" value= "on" onclick= "Checkall (this.form)" ><font C Olor= "#FF9900" > select all messages Displayed </font></p>
</td>
<center>


</tr>
</table>
</form>
2, delete the file del.asp
<%
' This line writes the code that connects the database
Dim Id,strid
Strid= ""
For each Strid in Request.Form ("tradename")
Id=cint (Strid)
If strid<> "" Then
Delrs = Server.CreateObject ("ADODB"). Recordset ")
Conn.execute "Delete from Tbname where id=" &cstr (ID)
Strid= ""
End If
Next

Conn.close
Set Conn = Nothing
Response.Redirect "successfully deleted!" "
%>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.