Set

The Set method takes the name of a counter and an integer, sets the counter to the value of the integer, and returns the new value. If the counter doesn't exist, Counters.Set creates it and sets it to the value of the integer.

To retrieve the value of a counter, use Counters.Get. To increment a counter by 1, use Counters.Increment.

Syntax

Counters.Set( CounterName, int )

 

Parameters
CounterName
A string containing the name of the counter.
int
The new integer value for CounterName.
Example

The following code resets the votes:

--- Counters_Set.asp ---

<HTML>
<HEAD><TITLE>Voting for Colors</TITLE></HEAD>
<BODY>
<%
  red = Request.QueryString("red")
  green = Request.QueryString("green")
  blue = Request.QueryString("blue")
  ' The Counters object was instantiated in Global.asa.
  If IsNumeric(red) Then
    Counters.Set "redcounter", red
  End If
  If IsNumeric(green) Then
    Counters.Set "greencounter", green
  End If
  If IsNumeric(blue) Then
    Counters.Set "bluecounter", blue
  End If
%>
<H3>Doctor the Vote:</H3>
<FORM NAME="Doctoring the Vote" METHOD="GET" ACTION="Counters_Set.asp">
Red <input type="TEXT" NAME="red"><BR>
Green <input type="TEXT" NAME="green"><BR>
Blue <input type="TEXT" NAME="blue"><BR>
<BR><INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
<H3>Current Vote Tally:</H3>
Red: <% =Counters.Get("redcounter") %><BR>
Green: <% = Counters.Get("greencounter") %><BR> 
Blue: <% = Counters.Get("bluecounter") %>
</BODY>
</HTML>
 
See Also

Get, Increment, Remove


© 1997-2001 Microsoft Corporation. All rights reserved.