Counter

13 views
Skip to first unread message

Troy Murray

unread,
Mar 22, 2012, 10:53:36 AM3/22/12
to ra...@googlegroups.com
I'm struggling today with what seems like a very basic operation but it doesn't seem to work.  Perhaps someone would be kind enough to point out what I'm doing wrong as I can't seem to figure out this basic task.

<cfset x = 5>
<cfset x = x + 1 />  = works and results in 6
<cfset x = x - 1 />  = results in 0

I'm on Railo 3.3.1.000

--
Troy Murray

Matt Quackenbush

unread,
Mar 22, 2012, 10:57:23 AM3/22/12
to ra...@googlegroups.com
I cannot answer why that is not working as expected, but give this a try as a workaround:

<cfset x = 5 />
<cfset x++ />
<cfset x-- />

Jean Moniatte

unread,
Mar 22, 2012, 11:01:27 AM3/22/12
to ra...@googlegroups.com
Hello,

Your code works as expected for me with Railo 3.3.1.000 final:

<cfset x = 5>
<cfoutput><pre>#x#</pre></cfoutput>
<cfset x = x + 1 />
<cfoutput><pre>#x#</pre></cfoutput>
<cfset x = x - 1 />
<cfoutput><pre>#x#</pre></cfoutput>

Results in:
5
6
5

Is it part of a cfc or a regular template?

Thanks,
Jean
--
Jean Moniatte
UGAL

Troy Murray

unread,
Mar 22, 2012, 11:05:24 AM3/22/12
to ra...@googlegroups.com
Here's the full code:

<cfoutput query="answerlists" group="id">
<tr>
<td>
#name#
</td>
<td>
<cfset str = "">
<cfoutput>
<cfset str = str & #value# & ",">
</cfoutput>
<cfset x = Len(str)>
<cfset x-- />
#Left(str, x)#
</td>
</tr>
</cfoutput>

I just restarted Tomcat/Railo and it still gives me the following error message:
"parameter 2 of the function left must be a positive number now [0]"

Ever been on a project so long your eyes start to cross even with the simple things?  Yeah, that's me right now.
--
Troy Murray

Matt Quackenbush

unread,
Mar 22, 2012, 11:05:11 AM3/22/12
to ra...@googlegroups.com
BTW, I too just checked on 3.3.1.000, and the results mirror Jean's.

Troy Murray

unread,
Mar 22, 2012, 11:07:58 AM3/22/12
to ra...@googlegroups.com
OK, thanks.
--
Troy Murray

Matt Quackenbush

unread,
Mar 22, 2012, 11:11:47 AM3/22/12
to ra...@googlegroups.com
Based upon that code and that error, I'm going to say that the result of <cfset x = Len(str)> is 1, meaning that str == ",". Then when you decrement x, it becomes 0.

Give this a whirl...


<cfoutput query="answerlists" group="id">
<tr>
    <td>
        #name#
    </td>
    <td>
    <cfset str = "">
    <cfoutput>
    <cfset str = str & #value# & ",">
    </cfoutput>
    <cfset x = Len(str)>
    <cfset x-- />
<cftry>
    #Left(str, x)#
    <cfcatch>
        <cfdump var="#str#" />
        <cfabort />
    </cfcatch>
</cftry>
    </td>
</tr>
</cfoutput>

Troy Murray

unread,
Mar 22, 2012, 11:15:33 AM3/22/12
to ra...@googlegroups.com
You were correct, thanks.

--
Troy Murray

Troy Murray

unread,
Mar 22, 2012, 11:20:13 AM3/22/12
to ra...@googlegroups.com
I'm sorry that sounded unappreciative to me.

Jean and Matt, thank you for taking a few minutes of time out of your busy day to help me with trying to resolve the problem I was having.  I realize that you didn't have to, but were willing to do that.  Thank you again.




--
Troy Murray

Matt Quackenbush

unread,
Mar 22, 2012, 11:26:07 AM3/22/12
to ra...@googlegroups.com
LOL. Dood, I have to say, I've been active on various forums/lists for over a decade, and that might just be the best "thank you" ever. To that, I say "no problem! always glad to help!". :-)


P.S. FWIW, I didn't think it was unappreciative at all. Cheers nonetheless! ;-)
Reply all
Reply to author
Forward
0 new messages