ASP the simplest and most practical counter _ application Tips

Source: Internet
Author: User
Tags readline
Just looking for a counter, because the site is too little traffic, put a counter in there is indeed a bit shabby, so the call can only make a simple point, you can visit once on the record to support Men Men first. Originally I had a, but depressed is incredibly can not find, in the Internet so a lap, finally is done, the specific program code as follows.
The count.asp code is:

Copy Code code as follows:

<%
Option Explicit
Dim fs,filename,txt,content,total,counter_lenth
Counter_lenth=1 ' Sets the minimum length of the data to display, if less than the actual length, whichever is the actual length
Set Fs=server.createobject ("Scripting.FileSystemObject")
Filename=server. MapPath ("Count.txt")
If not FS. FileExists (filename) Then
Fs. CreateTextFile Filename,true,true
Set TXT=FS. OpenTextFile (Filename,2,true)
Txt.write 0 ' If there is no file to save the data, create a new file and write to data 0
Set fs=nothing
End If

Set TXT=FS. OpenTextFile (filename)
If txt. AtEndOfStream Then
Application ("Counter") =0 ' if there is no data in the file, initialize the value of application (' Counter ') (for fault tolerance)
Else
Application ("Counter") =txt.readline
End If

Application.Lock
Application ("Counter") = Application ("Counter") + 1
Application.UnLock


function Save_ ' Save count functions
Set Fs=server.createobject ("Scripting.FileSystemObject")
Filename=server. MapPath ("Count.txt")
Content=application ("Counter")
Set TXT=FS. OpenTextFile (Filename,2,true)
Txt.write Content
Set fs=nothing
End Function

Save_ ' call save function to save data

function Digital (counter) ' Show data functions
Dim I,mystr,scounter
Scounter = CStr (counter)
For i = 1 to Counter_lenth-len (Scounter)
MyStr = mystr & "0"
' MyStr = mystr & ' "' If there is a picture, this statement can be invoked
Next
For i = 1 to Len (Scounter)
MyStr = mystr & Mid (Scounter, I, 1)
' MyStr = mystr & ' "' if there is a picture, can be invoked with this statement
Next
Digital = MyStr
End Function

function Count_show ' Read count functions
Set Fs=server.createobject ("Scripting.FileSystemObject")
Filename=server. MapPath ("Count.txt")
Set Txt=fs.opentextfile (filename,1,true)
Total=txt.readline
Total=cint (total)
' Response.Write Total
Response.Write Digital (total) calls the Display function
Set fs=nothing
End Function

%>



Then create a new count.txt (must be the same level as the count.asp), open the file and enter any number in it (don't be too ruthless), and then add the top of the page that needs to display the counter
Copy Code code as follows:

<!--#include file= "count.asp"-->


Finally, add the code where you want to display the counter
Copy Code code as follows:

<%=count_show%>


It's OK.
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.