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

Unable to out value of variable using Evaluate...

New Here ,
Aug 19, 2009 Aug 19, 2009

<cfcontent type="application/vnd.ms-excel">
<cfset count = 0>
<cfloop index="Add" from="1" to="1" step="1">
    <cfset count = count + 1>
<cfset Number = 'Form.inj_#count#'>
<cfset num = #Number#>
<cfset tick = 'Form.tick_#count#'>
<cfset sk = #tick#>
<cfset Quality = 'Form.quality_#count#'>
    <cfset qa = #Quality#>
<cfset description = 'Form.description_#count#'>
<cfset des = #description#>
  <cfoutput>
<table border="1" width="100%">
<tr>
<td align="center">#count#</td>
<td align="center">#Evaluate('sk')#</td>
<td align="center">#Evaluate('qa')#</td>
<td align="center">#Evaluate('des')#</td>
</tr>
</table>
</cfoutput>
</cfloop>

TOPICS
Getting started
1.3K
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

correct answers 1 Correct answer

Valorous Hero , Aug 19, 2009 Aug 19, 2009

Having very little idea what you are trying to do, that looks like a clasic case where array notation would be used.

<cfcontent type="application/vnd.ms-excel">
<cfset count = 0>
<cfloop index="Add" from="1" to="1" step="1">
  <cfset count = count + 1>
  <cfoutput>
<table border="1" width="100%">
<tr>
<td align="center">#count#</td>
<td align="center">#Form["tick_" & count]#</td>
<td align="center">#Form["quality_" & count]#</td>
<td align="center">#Form["description_" & count]#</td>
</tr>
</table>
</cfoutput
...
Translate
Valorous Hero ,
Aug 19, 2009 Aug 19, 2009

Having very little idea what you are trying to do, that looks like a clasic case where array notation would be used.

<cfcontent type="application/vnd.ms-excel">
<cfset count = 0>
<cfloop index="Add" from="1" to="1" step="1">
  <cfset count = count + 1>
  <cfoutput>
<table border="1" width="100%">
<tr>
<td align="center">#count#</td>
<td align="center">#Form["tick_" & count]#</td>
<td align="center">#Form["quality_" & count]#</td>
<td align="center">#Form["description_" & count]#</td>
</tr>
</table>
</cfoutput>
</cfloop>

That is my best guess at translating your very confusing code.

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
New Here ,
Aug 19, 2009 Aug 19, 2009

now its giving this message

Element tick_1 is undefined in a Java object of type class coldfusion.filter.FormScope.

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
Engaged ,
Aug 19, 2009 Aug 19, 2009

You don't tell us what the code generates, and why you think it's erroneous.

Time to do a lot of <cfdump>ing...  You should never assume that you know what value a particular variable contains at any particular point.  You must L{=)(=)K AND SEE.

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
New Here ,
Aug 19, 2009 Aug 19, 2009

Hi

the code dont generate error, It will output Form.quality_1 and look through it but not value of that variable..

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
Engaged ,
Aug 19, 2009 Aug 19, 2009

Here are some of the things that I do...

  • You definitely need to use IsDefined() to see if a variable actually exists.  Do not assume that it does.  (Notice that the argument to this function is a character-string containing a variable's name.)

  • I am a big fan of using StructKeyExists() and of working with things (including FORM) as the structures they inherently are.  You can use both "dot-notation" and "square-bracket array/hash notation" when dealing with structures.  I'll assign a variable or structure-element name to a character string (so that I'm not repeating repeating myself myself), then see if the element exists, then use the square-bracket notation style to retrieve the structure-element named by that variable.  (Documentation reference:   "ColdFusion 8 Developer's Guide" http://livedocs.adobe.com/coldfusion/8/htmldocs/, "Using Arrays and Structures," "About Structures," "Structure Notation.")

  • Sometimes, it is actually quite handy to just do something knowing that an exception might "occasionally" occur, and to trap that exception using the <cftry>/<cfcatch> construct.  If the exception that might happen is, ahem, "the exception, rather than the rule," then you can sometimes do well to "just plunge right in, having first prudently placed a nice trampoline underneath you."  You just need to be sure that, if an exception does happen, you haven't just drooled some half-finished HTML out to the user's screen.
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
Explorer ,
Aug 19, 2009 Aug 19, 2009
LATEST

Hi,

Try this:

<cfcontent type="application/vnd.ms-excel">
<cfset count = 0>
<cfloop index="Add" from="1" to="1" step="1">
    <cfset count = count + 1>
<cfset ThisNumber = "">
<cfif StructKeyExists(Form, "Inj_" & Count)>
      <cfset ThisNumber = Form["Inj_" & Count]>
</cfif>
<cfset ThisTick = "">
<cfif StructKeyExists(Form, "Tick_" & Count)>
      <cfset ThisTick = Form["Tick_" & Count]>
</cfif>
<cfset ThisQuality = "">
<cfif StructKeyExists(Form, "Quality_" & Count)>
      <cfset ThisQuality = Form["Quality_" & Count]>
</cfif>
<cfset ThisDescription = "">
<cfif StructKeyExists(Form, "Description_" & Count)>
      <cfset ThisDescription = Form["Description_" & Count]>
</cfif>
<cfoutput>
<table border="1" width="100%">
<tr>
<td align="center">#count#</td>
<td align="center">#ThisTick#</td>
<td align="center">#ThisQuality#</td>
<td align="center">#ThisDescription#</td>
</tr>
</table>
</cfoutput>
</cfloop>

The error indicated that the tick_1 form variable wasn't there, so I'm guessing it was a checkbox. You just have to expect that and code around it by either checking for it's existence first (like I did above), or using CFParam to ensure it exists.

Swift

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