Using cfloop to intialize variables

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Re: Using cfloop to intialize variables

    <cfloop index="i" from="1" to="29">
    <cfset "Q#i#1" = 0>
    <cfset "Q#i#2" = 0>
    <cfset "Q#i#3" = 0>
    </cfloop>
    <cfloop index="i" from="1" to="29">
    <cfset thisvar = #evaluate("'Q'&i&'1'")#>
    <cfoutput>#evaluate("'Q'&i&'1'")# - #evaluate(thisvar)#<br></cfoutput>

    </cfloop>

    philh Guest

  2. Similar Questions and Discussions

    1. cfloop
      The goal is to insert a record into table 'atd', which contains a document id and an associate id, for each document (38) and associate (150). So...
    2. Cfloop..
      I am trying to loop over a list: <cfquery name="updsyllabus" datasource="#arguments.syl.dsn#"> UPDATE #arguments.syl.tname# SET <cfloop...
    3. to cfloop or not to cfloop?
      :confused; I have a list of checkboxes from a form, and a submit button for "Batch Print" The var is "SelectList" and comes out as comma dilimited....
    4. cfloop from query
      Hi there! I need a little help here. I have to change 'TraveAgencyNumber' to 'TravelAgencyName' Through this query output (GetLog) I only get the...
    5. CFLOOP and dynamic variables
      Hi, have a simple problem - and I cannot find a simple answer! I am looping through a list of fields returned from a form. FORM.FIELDLIST via...
  3. #2

    Default Re: Using cfloop to intialize variables

    > <cfset Q#i#1 = 0>
    > But, I get an error on the pound sign. Any idea why?
    Possibly because it's invalid syntax, I should think ;-)

    Try this:

    <cfset "Q#i#1" = 0>

    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000334.htm[/url]
    --

    Adam
    Adam Cameron Guest

  4. #3

    Default Re: Using cfloop to intialize variables

    While this method did create all the variables, instead on each variable equaling zero, it equals it's name. So, the value of variable Q11 is Q11, value of Q12 is Q12, etc.
    DaSpaz Guest

  5. #4

    Default Re: Using cfloop to intialize variables

    > <cfset thisvar = #evaluate("'Q'&i&'1'")#>
    You don't need to do this.

    <cfset thisvar = variables["Q#i#1")>
    > <cfoutput>#evaluate("'Q'&i&'1'")# - #evaluate(thisvar)#<br></cfoutput>
    Similarly here.

    I would say that about 95% of the time that you might think you need to use
    evaluate(), you really don't need to.

    --

    Adam
    Adam Cameron Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139