ASP FAQs and Answers (7)

Source: Internet
Author: User
Answer | Question 1. Category: Grammar application
Problem Description: Find the number of characters between two string occurrences
Solution:

function Findstringtimes (strcontent,start_string,end_string) ' start_string and end_string number of characters out of time
' Written by Jaron
Findstringtimes = UBound (Split (strcontent,start_string))
End Function

Example: Find out how many pictures are in the following string
Response.Write Findstringtimes (HTML, "



2. The function of traversing the directory and the files in the directory

<%
function Bianli (path)
Set Fso=server. CreateObject ("Scripting.FileSystemObject")

On Error Resume Next
Set OBJFOLDER=FSO. GetFolder (PATH)

Set Objsubfolders=objfolder.subfolders

For each objsubfolder in Objsubfolders

Nowpath=path + "\" + objsubfolder.name

Response.Write Nowpath

Set Objfiles=objsubfolder.files

For each objfile in Objfiles
Response.Write "<br/>---"
Response.Write Objfile.name
Next
Response.Write "<p>"
Bianli (Nowpath) ' Recursive

Next
Set objfolder=nothing
Set objsubfolders=nothing
Set fso=nothing
End Function
%>
<%
Bianli ("D:") ' Traverse D: Disk
%>




3. Generate a repeat number

Sub Calcapiao ()
Dim Strcaipiaonoarr () as String
Dim strSQL as String
Dim Strcaipiaono as String
Strcaipiaono = " 01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33 "
Dim Strtemparr (7) as String
Dim Strzhongjiangarr (7) as String
Strcaipiaonoarr = Split (Strcaipiaono, ",")
Dim Intrand as Integer
Dim I as Integer
Dim J as Integer
i = 0
Dim Find as Boolean
Do While True
Find = False
Randomize
Intrand = Int ((Rnd) + 1)
For j = 0 to I-1
If Strtemparr (j) = CStr (Intrand) Then
Find = True
End If
Next
If not find Then
Strtemparr (j) = CStr (Intrand)
Strzhongjiangarr (i) = CStr (Intrand)
' Text1 (i) = Strzhongjiangarr (i)
i = i + 1
If i = 7 Then
Exit do
End If
End If
Loop
End Sub



4. Download any files (especially IE associated with the open)
<%
Dim Stream
Dim Contents
Dim FileName
Dim Fileext
Const adTypeBinary = 1
filename = request.querystring ("filename")
If FileName = "" Then
Response.Write "Invalid filename."
Response.End
End If
' Below is a file that you don't want to download
Fileext = Mid (filename, InStrRev (filename, ".") + 1)
Select case UCase (Fileext)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
Response.Write "protected file, cannot download."
Response.End
End Select
' Download this file
Response.Clear
Response.ContentType = "Application/octet-stream"
Response.AddHeader "Content-disposition", "attachment"; Filename= "& FileName
Set Stream = server. CreateObject ("ADODB.") Stream ")
Stream.type = adTypeBinary
Stream.open
Stream.loadfromfile Server.MapPath (FileName)
While not Stream.eos
Response.BinaryWrite Stream.read (1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>


5. Background Color transform
<form>
<p><input type= "button" value= "Background color transform" onclick= "Bgbutton ()" ></p>
</form>
<script>function Bgbutton () {
if (document.bgcolor== #00ffff)
{document.bgcolor= #ffffff;}
Else{document.bgcolor= #00ffff;}
}
</script>



6. Click to open a new window
<form>
<p><input type= "button" value= "open new Window" onclick= "NewWindow ()" ></p>
</form>
<script language= "JavaScript" ><!--
function NewWindow () {window.open ("http://www.mcmx.com";;;, "", "Height=240,width=340,status=no,location=no, Toolbar=no,directories=no,menubar=no ");}
--></script></body>



7. Pagination Code:
<% This program file name is:pages.asp%>
<% contains the ADO constant table file Adovbs.inc, which can be copied from the \program Files\Common Files\System\ado directory%>
<!--#Include file= "Adovbs.inc"-->
<%* Establish a database connection, this is the Oracle8.05 database
Set conn=server.createobject ("ADODB. Connection ")
Conn. Open "Prov



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.