You haven't made your counter variable persistent.  Every time someone makes
a new request of your application, Application.cfm creates a new variable
called "counter" and sets it equal to 0.  You need to make your variable
persistent.  And since you want it to work across multiple users, it should
probably persist in the APPLICATION scope.

So, your Application.cfm should look something like:

        <CFIF NOT IsDefined("APPLICATION.Counter")>
                <CFLOCK TYPE="Exclusive" NAME="lckCreateCounter">
                        <CFSET APPLICATION.Counter = 0>
                </CFLOCK>
        </CFIF>

Your action page should look something like:

        <!--- Get counter value --->
        <CFLOCK TYPE="ReadOnly" NAME="lckReadCounter">
                <CFSET Counter = APPLICATION.Counter>
        </LOCK>

        <CFIF Counter EQ 6>
                <!--- Increment counter --->
                <CFLOCK TYPE="Exclusive" NAME="lckWriteCounter">
                        <CFSET APPLICATION.Counter = 0>
                </CFLOCK>

                <!--- ***** show survey code ***** --->
        <CFELSE>
                <!--- Increment counter --->
                <CFLOCK TYPE="Exclusive" NAME="lckWriteCounter">
                        <CFSET APPLICATION.Counter = APPLICATION.Counter + 1>
                </CFLOCK>
        </CFIF>


--
Mosh Teitelbaum
evoch, LLC
Tel: (301) 625-9191
Fax: (301) 933-3651
Email: [EMAIL PROTECTED]
WWW: http://www.evoch.com/


> -----Original Message-----
> From: Clark, Aimee [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 26, 2002 4:03 PM
> To: CF-Talk
> Subject: Using a counter variable
>
>
> I have an application in which I want every 7th record closed in
> a table to
> generate an email asking the user to participate in a survey.
>
> I have <cfset counter = 0> in the application.cfm file.
>
> I have <cfset counter = counter +1> in my action page right after
> an update
> that is done to the table.
>
> Then I have <cfif counter EQ 7>
>       execute generating email
>       then it resets the counter back to 0
>
> However my counter is not incrementing at all. It just keep staying at 1.
> I'm not sure why. Can someone provide some assistance with this?
>
> Thank you,
> Aimee' Clark
> Web Developer
> Stinson Morrison Hecker
>
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Reply via email to