4 Replies Latest reply on May 29, 2008 10:27 AM by CTek-Media.com

    Variables in Variables

    John_Nemo
      I have some code that creates variables for each of the next 12 months. This is an example for the second month.

      <CFSET VARIABLES.Date1 = DateFormat(DateAdd("M", 1, Now()))>
      <CFSET VARIABLES.numDays1 = DaysInMonth(Date1)>
      <CFSET VARIABLES.Month1 = Month(Date1)>
      <CFSET VARIABLES.MonthString1 = MonthAsString(Month1)>
      <CFSET VARIABLES.MonthStrg1 = Left(MonthString1, 3)>
      <CFSET VARIABLES.Year1 = Year(Date1)>
      <CFSET VARIABLES.BegDate1 = "#Month1#/1/#Year1#">
      <CFSET VARIABLES.BegDate1 = CreateODBCDate(BegDate1)>
      <CFSET VARIABLES.EndDate1 = "#Month1#/#numDays1#/#Year1#">
      <CFSET VARIABLES.EndDate1 = CreateODBCDate(EndDate1)>

      Now I could write this all out and replace the integer "1" with "2", "3" etc. over and over but it makes sense to save typing and put this in a loop.

      Problem is I can't seem to figure out how.

      <CFLOOP FROM="1" TO="11" INDEX="i">
      <CFSET VARIABLES.Date#i# = DateFormat(DateAdd("M", #i#, Now()))> etc. ???
      </CFLOOP>

      This line looks particulary tricky:
      <CFSET VARIABLES.EndDate1 = "#Month1#/#numDays1#/#Year1#">

      How do you put a variable in a variable? Something to do with evaluate?

      surprised

      Thank you,

      John