Counter | design | detailed
(iii) Image counter separated from the page People's pursuit is endless, perhaps you need a more personalized graphics counter, rather than a simple text digital counter. No problem, now let's take a look at how ASP is used to achieve the function of graphics counters. In order to realize the graph counter, the key point is how to realize the conversion of the data value in the counter file to the corresponding image representation. Because the decimal number has a total of 10 different number of 0,1,2,3,4,5,6,7,8,9, we need to have 10 corresponding image, and the image of the file name to correspond with the number shown, such as 0 corresponding digital image of the file name is 0.gif,1 corresponding is 1.gif, ... (Images can be made using Photoshop tools, or downloaded from the web). Here we'll use the VBScript function len (string | varname), MID (String,start[,length]). The number of digits of the counter value can be obtained by Len (counter), and the number on the first bit of the counter value may be obtained by mid (counter,i,1), and we can use this value to invoke the corresponding digital image. With the FOR Loop statement, it is not difficult to get the numbers on each bit of counter values and convert them into corresponding digital images, so that we can convert the text values to the image numbers. The following is an example of an image counter written in ASP, because most of the code has been analyzed before, so only some of the statements are commented in the code.
Imgcounter.asp code for Image counter separated from page:
<% @language = "VBScript"%>
<%
Dim images (20)
' defines an array that holds statements that display each digit image
Countfile=server.mappath ("Imgcounter.txt")
Set fileobject=server.createobject ("Scripting.FileSystemObject")
Set Out=fileobject.opentextfile (Countfile,1,false,false)
Counter=out.readline
Out.close
SET fileobject=server.createobject ("Scripting.FileSystemObject")
Set Out=fileobject.createtextfile (Countfile,true,false)
Application.Lock
counter= counter + 1
Out.writeline (counter)
Application.UnLock
Countlen=len (counter)
' Gets the number of digits of the counter value
For I=1 to Countlen
Images (i) = "</img>"
' The Display code (HTML) of the numeric corresponding image on each bit is obtained by the Loop statement, and it exists in the array
' Please note the actual server and directory path of image when using
Response.Write "document.write (' &images (i) &");
' Call function document.write output the HTML code that displays the digital image
Next
Out.close
%>
Add the following code to the page you want to count:
<p>
You are the first
<script language= "JavaScript" src= "http://202.101.209.75/asptemp/counter/imgcounter.asp";>
Note the server and directory path where the ASP counters are located when referencing.
</script>
Guest
</p>
Note: The above ASP counters are tested through Windows NT Server 4.0 (Chinese)/IIS3.0. Any of the following environments can perform asp:
One, Windows NT Server 4.0/iis3.0 above
Second, Windows NT WorkStation 4.0/microsoft Peer Web Service3.0 above
Third, Windows 95/98/microsoft Personal Web Server 1.0a above
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.