|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Incrementing a variable
Hi,FlashGuy 12/17/02 07:15 A Youll need to do something like...Mike Townend 12/17/02 07:26 A Hmm...OK I just tried it out and its not quite working the way I wanted it to.FlashGuy 12/17/02 07:47 A What do you need it to do?Mike Townend 12/17/02 07:57 A Are you trying to get this result?webguy 12/17/02 07:29 A > Are you trying to get this result?FlashGuy 12/17/02 07:39 A That code looks ok to me , how is it not working ? An error ?webguy 12/17/02 08:00 A No...no error. code works just fine.FlashGuy 12/17/02 08:05 A Use a session instead of a application scopewebguy 12/17/02 08:14 A OK...but every time I hit the refresh it increments. I don't want that. Also everytime I drill down into the directory structure I also want the counter to decrement if I click on aFlashGuy 12/17/02 08:35 A > Probably too much work, right?Thomas Chiverton 12/17/02 11:28 A That's because on every page request you reset the value to zeroTaz 12/17/02 07:31 A I'm trying to set a variable based on were I am in my directory structure.FlashGuy 12/17/02 07:54 A You might want to look at something like...Mike Townend 12/17/02 08:16 A SpookyTaz 12/17/02 08:26 A Your application.cfm is loaded on every refresh so the variable is set toDDB Lists 12/17/02 07:34 A If I close the brower the application.child variable doesn't get cleared?FlashGuy 12/17/02 07:56 A Flash guy - Use a session variable.Stephen Moretti 12/17/02 08:24 A It will always get reset back to 0 with every page request.Adrian Lynch 12/17/02 07:25 A It looks like you're resetting the variable each time a page loads....Paolo Cesana 12/17/02 07:32 A Are you using fusebox?John McCosker 12/17/02 08:13 A Hi, For some reason I can't get my variable to increment when my page is reloaded. I have the following in my application.cfm file <cfset child = 0> In my index.cfm file I have the following. <cfset child=child + 1> Everytime I refresh the page manually or by using an <a href within mu file to reload mu index.cfm it doesn't increment? --------------------------------------------------- Colonel Nathan R. Jessop Commanding Officer Marine Ground Forces Guatanamo Bay, Cuba --------------------------------------------------- Youll need to do something like... In Application.cfm <CFLOCK TIMEOUT="5" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="APPLICATION"> <CFPARAM NAME="Application.child" DEFAULT="0"> </CFLOCK> And in the index file <CFLOCK TIMEOUT="5" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="APPLICATION"> <CFSET Application.child = Application.Child + 1> </CFLOCK> HTH Hi, For some reason I can't get my variable to increment when my page is reloaded. I have the following in my application.cfm file <cfset child = 0> In my index.cfm file I have the following. <cfset child=child + 1> Everytime I refresh the page manually or by using an <a href within mu file to reload mu index.cfm it doesn't increment? --------------------------------------------------- Colonel Nathan R. Jessop Commanding Officer Marine Ground Forces Guatanamo Bay, Cuba --------------------------------------------------- Hmm...OK I just tried it out and its not quite working the way I wanted it to. ----- Excess quoted text cut - see Original Post for more ----- What do you need it to do? It does pretty much what your orignal code does... Ive just moved it to a persistant scope... Hmm...OK I just tried it out and its not quite working the way I wanted it to. ----- Excess quoted text cut - see Original Post for more ----- Are you trying to get this result? 1st view of index.cfm value=1 2nd view of index.cfm value=2 3rd view of index.cfm value=3 If so you are doing to wrong because this is what you are actually doing 1st view of index.cfm appliation.cfm sets child = 0 index.cfm sets child = child + 1 = 1 2nd view of index.cfm appliation.cfm sets child = 0 index.cfm sets child = child + 1 = 1 3rd view of index.cfm appliation.cfm sets child = 0 index.cfm sets child = child + 1 = 1 Webguy ----- Excess quoted text cut - see Original Post for more ----- > Are you trying to get this result? > > 1st view of index.cfm value=1 > 2nd view of index.cfm value=2 > 3rd view of index.cfm value=3 > Yes. > If so you are doing to wrong because this is what you are actually doing OK..I see...how would I go about doing the above? ----- Excess quoted text cut - see Original Post for more ----- That code looks ok to me , how is it not working ? An error ? ----- Excess quoted text cut - see Original Post for more ----- WG Detainees in Guantánamo: As One Year Anniversary Nears, US Bars Scrutiny By Human Rights Group http://www.amnestyusa.org/news/2002/usa12132002.html ----- Excess quoted text cut - see Original Post for more ----- No...no error. code works just fine. Its not not behaving like I want it to. ----- Excess quoted text cut - see Original Post for more ----- Use a session instead of a application scope In Application.cfm <CFLOCK TIMEOUT="5" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="session"> <CFPARAM NAME="session.child" DEFAULT="0"> </CFLOCK> And in the index file <CFLOCK TIMEOUT="5" THROWONTIMEOUT="No" TYPE="EXCLUSIVE" SCOPE="session"> <CFSET session.child = session.Child + 1> </CFLOCK> WG ----- Excess quoted text cut - see Original Post for more ----- OK...but every time I hit the refresh it increments. I don't want that. Also everytime I drill down into the directory structure I also want the counter to decrement if I click on a link to go back. Probably too much work, right? ----- Excess quoted text cut - see Original Post for more ----- > Probably too much work, right? Do-able with the ListLen posted earlier. -- Thomas C "Does google know ?" That's because on every page request you reset the value to zero What are you trying to do? Taz > Hi, > > For some reason I can't get my variable to increment when my page is reloaded. ----- Excess quoted text cut - see Original Post for more ----- file to reload mu index.cfm it doesn't increment? ----- Excess quoted text cut - see Original Post for more ----- I'm trying to set a variable based on were I am in my directory structure. At initial loading of my index.cfm I would set a variable to "0" WHen I click on a link and "drill-down" into the directory I want that variable incremented. At the same time if I go backup up in the directorure structure I want the variable decremented. Example: D:\dir1 [0] D:\dir2 [0] Click on D:\dir1 D:D:\dir1\test1 [1] D:\dir1\test2 [1] Click on D:\dir1\test D:D:\dir1 [1] D:\dir1\test1 [2] ----- Excess quoted text cut - see Original Post for more ----- You might want to look at something like... <CFSET Child = ListLen(GetDirectoryFromPath(ExpandPath("*.*)), "\")> Or something similar HTH I'm trying to set a variable based on were I am in my directory structure. At initial loading of my index.cfm I would set a variable to "0" WHen I click on a link and "drill-down" into the directory I want that variable incremented. At the same time if I go backup up in the directorure structure I want the variable decremented. Example: D:\dir1 [0] D:\dir2 [0] Click on D:\dir1 D:D:\dir1\test1 [1] D:\dir1\test2 [1] Click on D:\dir1\test D:D:\dir1 [1] D:\dir1\test1 [2] ----- Excess quoted text cut - see Original Post for more ----- Spooky You ought to do a ListLen() on the template path using '\' as the delimiter Taz Your application.cfm is loaded on every refresh so the variable is set to zero every time. You should put it in a persistant scope and check for it's existance: <cif not isdefined("application.child")> <cfset application.child = 0> </cfif> and <cfset application.child = application.child + 1> > I have the following in my application.cfm file > <cfset child = 0> > In my index.cfm file I have the following. > <cfset child=child + 1> > Everytime I refresh the page manually or by using an <a href within mu file to reload mu index.cfm it doesn't increment? If I close the brower the application.child variable doesn't get cleared? ----- Excess quoted text cut - see Original Post for more ----- Flash guy - Use a session variable. DDBLists - you need cflocks on that code even in cfmx. Its the classic example of a race condition. > If I close the brower the application.child variable doesn't get cleared? > > > > > > Your application.cfm is loaded on every refresh so the variable is set to ----- Excess quoted text cut - see Original Post for more ----- It will always get reset back to 0 with every page request. Hi, For some reason I can't get my variable to increment when my page is reloaded. I have the following in my application.cfm file <cfset child = 0> In my index.cfm file I have the following. <cfset child=child + 1> Everytime I refresh the page manually or by using an <a href within mu file to reload mu index.cfm it doesn't increment? --------------------------------------------------- Colonel Nathan R. Jessop Commanding Officer Marine Ground Forces Guatanamo Bay, Cuba --------------------------------------------------- It looks like you're resetting the variable each time a page loads.... Use cfparam instead to set it once if you choose to place the init in application.cfm Also, you need to think about variable scope... Rgds Paolo Cesana IT Development Mgr. "Electricity is not the result of a series of upgrades to the candle" Auth. unknown Miami International Forwarders (MIF) Phone: (305)594-0038 Ext. 7326 Fax: (305)593-0431 mailto:paoloc@mif.com <mailto:paoloc@mif.com> http://www.mif.com <http://www.mif.com/> Hi, For some reason I can't get my variable to increment when my page is reloaded. I have the following in my application.cfm file <cfset child = 0> In my index.cfm file I have the following. <cfset child=child + 1> Everytime I refresh the page manually or by using an <a href within mu file to reload mu index.cfm it doesn't increment? --------------------------------------------------- Colonel Nathan R. Jessop Commanding Officer Marine Ground Forces Guatanamo Bay, Cuba --------------------------------------------------- Are you using fusebox? If you are you could use the fuseaction to determine if it increments or vise verca, e.g. D:\dir1 [0] fuseaction=thisFuse&counter=#attributes.counter# D:\dir2 [0] fuseaction=thisOtherFuse&counter=#attributes.counter# then in your app globals <CFPARAM NAME="attributes.counter" DEFAULT="0"> <cfwith expression="#attributes.fuseaction#"> <cfcase value="thisFuse"><CFSET attributes.counter=attributes.counter-1><cfcase> <cfcase value="thisOtherFuse"><CFSET attributes.counter=attributes.counter+1><cfcase> </cfswitch> if your not using fusebox, in your application.cfm <CFPARAM NAME="counter" DEFAULT="0"> <CFIF GetBaseTemplatePath() CONTAINS("dir1")> <CFSET counter=counter-1> <CFELSEIF GetBaseTemplatePath() CONTAINS("dir2")> <CFSET counter=counter+1> </CFIF> and then in you links you'll always have to pass via hidden form field, cookie, or url <a href="index.cfm?counter=#counter#>link</a> I think this is along the right path, J I'm trying to set a variable based on were I am in my directory structure. At initial loading of my index.cfm I would set a variable to "0" WHen I click on a link and "drill-down" into the directory I want that variable incremented. At the same time if I go backup up in the directorure structure I want the variable decremented. Example: D:\dir1 [0] D:\dir2 [0] Click on D:\dir1 D:D:\dir1\test1 [1] D:\dir1\test2 [1] Click on D:\dir1\test D:D:\dir1 [1] D:\dir1\test1 [2] ----- Excess quoted text cut - see Original Post for more -----
|
May 19, 2013
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||