ASP Programming Basics (15th): Counters

Source: Internet
Author: User
This component is used to create one or more counters that track the number of visits to a webpage or website. You can create only one counter component, but this component can have more than one counter.
Once a counter is created, it continues until it is deleted.
Counters are not automatically added when an event, such as accessing a page. You must use the Set and Increment methods to manually Set or increase the counter.
The counter is not limited by the scope. Once a counter is created, any page on the site can retrieve and control its values.
1. Counters. Set & Counters. Get
Counters. Set is mainly used to Set the initial value of the count, and Counters. Get is used to extract the count value.
1, counts_set.asp
<%
Set Counters = server. createobject ("MSWC. Counters ")
Counters. Set "cnbruce", 10
Counters. set "it365cn", 20
Counters. set "blueidea", 30
%>
<% = Counters. Get ("cnbruce") %> total visits to cnbruce.com <br>
Total visits <% = Counters. Get ("it365cn") %> to the it365cn.com website <br>
Total visits <% = Counters. Get ("blueidea") %> <br>

The usage is simple. First, "Counters = server. createobject ("MSWC. counters ") indicates that a Counters component connection is established. Counters. set "cnbruce", 10 indicates that the initial value "cnbruce" is counted as 10; Counters. get ("cnbruce") indicates to extract the record value named "cnbruce.
II. Counters. Increment
The function of this method is to add one key at a time. In the above example, when you refresh the page, the records are not added, so use the Increment method now.
2, counts_inc.asp
<%
Set Counters = server. createobject ("MSWC. Counters ")
%>
Total <% = Counters. Increment ("cnbruce") %> visits to cnbruce.com <br>
Total visits <% = Counters. Increment ("it365cn") %> to it365cn.com <br>
Total visits <% = Counters. Increment ("blueidea") %> <br>

The basic code is similar, mainly because the Counters. Increment function accumulates 1.
A simple voting system can be built based on accumulation.
3. vote. asp
<%
Set Counters = server. createobject ("MSWC. Counters ")
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.