Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple Dynamic Evaluation Question

New Here ,
Jul 25, 2008 Jul 25, 2008
Can someone show me how to reproduce this with a CFLOOP? I can't seem to get past the dynamic variable naming. Thanks!
320
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2008 Jul 25, 2008
deleted, it was wrong
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 25, 2008 Jul 25, 2008
LATEST
LionelR wrote:
> Can someone show me how to reproduce this with a CFLOOP?

Just think through what you need to do in general terms first. It seems as if you need take three variables:

colorID1, colorID2, colorID3

.. and split each one into two parts:

colorID1_1, colorID1_2
colorID2_1, colorID2_2
colorID3_1, colorID3_2

So roughly speaking you want to

1. Loop three times
2. Within each loop, split the current variable into two parts

The rest is just becomes a matter of constructing the dynamic variable names using array notation.

<cfloop from="1" to="3" index="suffix">
<cfset variables["colorid"& suffix &"_1"] = ListGetAt(variables["colorid"& suffix],1)>
<cfset variables["colorid"& suffix &"_2"] = ListGetAt(variables["colorid"& suffix], 2)>
</cfloop>

<cfdump var="#variables#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources