Skip to main content
Inspiring
October 16, 2008
Question

Question about arrays and loops

  • October 16, 2008
  • 2 replies
  • 297 views

Ok, I have the following code:

<cfif #url.e# eq 0>

<cfset classList=arraynew(2)>
<cfset classListLoop="A,B,C,D,E,U">
<cfset classLoopCount=1>
<cfloop list="#classListLoop#" delimiters="," index="i">
<cfset classList[#classLoopCount#][1]=#i#>
<!--- send to udf to count each rating occurance and assign
to variable --->
<cfinvoke component="components.ov_rating" method="rating"
returnvariable="result">
<cfinvokeargument name="tid" value="#url.tid#">
<cfinvokeargument name="dbfield" value="e_foil_rating">
<cfinvokeargument name="rating" value="#i#">
</cfinvoke>
<cfset classList[#classLoopCount#][2]=#result#>
<cfset classLoopCount=classLoopCount+1>
</cfloop>

<cfelse>
<cfloop from="1" to="2" index="j">
<cfset classList_#j#=arraynew(2)>
<cfset classListLoop="A,B,C,D,E,U">
<cfset classLoopCount=1>
<cfloop list="#classListLoop#" delimiters="," index="i">
<cfset classList_#j#[#classLoopCount#][1]=#i#>
</cfloop>
</cfloop>
</cfif>

What I'm trying to do on the <cfelse> is that if url.e eq 1, then there needs
to be 2 arrays setup. When I try the code after the <cfelse> I'm getting:

Invalid CFML construct found on line 30 at column 42.
ColdFusion was looking at the following text:
#

The CFML compiler was processing:

A cfset tag beginning on line 30, column 26.
A cfset tag beginning on line 30, column 26.
A cfset tag beginning on line 30, column 26.


The error occurred in D:\home\salleboise.com\wwwroot\tournament.cfm: line 30

28 : <cfelse>
29 : <cfloop from="1" to="2" index="j">
30 : <cfset classList_#j#=arraynew(2)>
31 : <cfset classListLoop="A,B,C,D,E,U">
32 : <cfset classLoopCount=1>


What am I missing??


    This topic has been closed for replies.

    2 replies

    Inspiring
    October 16, 2008
    change
    <cfset classList_#j#=arraynew(2)>
    to
    <cfset variables["classList_" & j]=arraynew(2)>

    you will have to similarly change your <cfset
    classList_#j#[#classLoopCount#][1]=#i#> line

    it also looks like you have forgotten to increment your classLoopCount
    variable in your cfelse part....

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    October 16, 2008
    Hello Azadi,


    > it also looks like you have forgotten to increment your classLoopCount
    > variable in your cfelse part....
    >
    > Azadi Saryev
    > Sabai-dee.com
    > http://www.sabai-dee.com/


    Yea, I haven't gotten that far yet, it wasn't forgotten, just not in there
    yet! ;)

    Thanks though


    Inspiring
    October 16, 2008
    > What am I missing??

    That this is illegal
    <cfset classList_#j#=...>

    To do this exact thing you must use array notation. (Well ok, you could
    also use evaluate -- but *don't* -- and I'm not going to show you how).

    <cfset variables['classList_' & j] = ...>


    But I wouldn't recommend that solution. Why not make classList itself
    an array and then just do this instead?

    <cfset classList = ...>