ASP programming into the first step (fifteen): Component Counters

xiaoxiao2021-03-06  37

This component is used to create one or more counters, which are used to track information of a web page or a certain number of websites. You can only create a counter component, but the component can have more than one counter. Once a counter is created, it will continue until it is deleted. The counter does not automatically increase when an event is accessed, for example. You must use the Set and Increment methods to manually set or grow counter. The counter is not subject to the scope. Once a counter is created, then any page on the site can retrieve and control it. 1. Counters.Set & Counters.getCounters.SET is mainly used to set the initial value of the count, and counter is used to extract the value of the count. 1, counts_set.asp

<% Set counters = server.createObject ("mswc.counters") Counters.set "CNBruce", 10Counters.Set "IT365CN", 20Counters.Set "Blueidea", 30%> A total of <% = Counters.get ("cnbruce" )%> Time access CNBRUCE.COM website
a total of <% = Counters.get ("IT365CN")%> Time access it365cn.com website
<% = Counters.get ("blueidea")%> Visit Blueidea.com Website

Usage is very simple, first, "counts = server.createObject (" mswc.counters "means a connection to establish a Counters component; Counters.SET" CNBRUCE ", 10 means that the countdown name" cnbruce "is 10; Counters.get ("cnbruce") indicates that the number of records named "cnbruce" is extracted. Second, the function of this method is: count each time you add one. In the previous example, you refresh the page, the count is not added, so now you have now replaced the increment method. 2, counts_inc.asp

<% Set counters = server.createObject ("mswc.counters")%> A total of <% = Counters.Increment ("cnbruce")%> Time access CNBRUCE.COM website
a total of <% = Counters.Increment ("IT365cn ")%> Time access it365cn.com website
a total of <% = Counters.Increment (" Blueidea ")%> Time Access Blueidea.com Website

The basic code is similar, mainly the functionality of Counters.Increment. It can be a simple voting system based on accumulation. 3, vote.asp

<% set counters = server.createObject ("mswc.counters") vote = request.QueryString ("site") counter> Vote for your favorite site:

cnbruce IT365CN < Input type = "radio" name = "site" value = "blueidea"> blueidea
current vote tally:
CNBRUCE: <% = Counters.Get ("cnbruce")%>
IT365CN: <% = Counters.get ("IT365CN")%>
Blueidea: <% = Counters.Get ("Blueidea")%>
The function is to submit a radio button, and the corresponding count value is Counters.Increment. 4. Remove.asp

<% set counters = server.createObject ("mswc.counters") vote = request.queryString ("site") Clear = Request.QueryString ("Clear") Counters.Increment (vote) if not clear = "". Remove ("cnbruce") Counters.Remove ("IT365CN") Counters.Remove ("Blueidea") End IF%> Vote for your favorite site: cnbruce IT356CN Blueidea
current vote tally:
cnbruce: <% = Counters.Get ("cnbruce ")%>
IT365CN: <% = Counters.Get (" IT365CN ")%>
Blueidea: <% = Counters.Get (" Blueidea ")%>

转载请注明原文地址:https://www.9cbs.com/read-70354.html

New Post(0)