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

Variable undefined

Explorer ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

Good morning I have a situation wherein  during an insert into my database, the variable that I created from an cfif/cfset throws an error. Am I missing something? My code is below...

<cfset gradepoint =VAL('#fcnpoint#') + VAL('#attitudepoint#') +

VAL('#guestpoint#') + VAL('#contactpoint#') + VAL('#attendancepoint#')

+ VAL('#nspoint#') + VAL('#foidpoint#') + VAL('#otherpoint#')>

<cfif "#gradepoint#" GTE "-20.45" AND "#gradepoint#" LTE "11.1"><cfset

maingrade= 'F'></cfif>

INSERT INTO squadreport (squid,  squgrade)

VALUES ('00', '#maingrade#')

</cfquery>

Views

477

Translate

Translate

Report

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 ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

If the CFIF condition is not met, #maingrade# will not be set.

You could CFPARAM #maingrade#, but this will not address the issue, it will just prevent the error.

^_^

Votes

Translate

Translate

Report

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
Community Expert ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

Wolfshade has hit the nail on its head. I would add the following. The code reads better as

<cfset gradepoint = val(fcnpoint) + val(attitudepoint) + val(guestpoint) + val(contactpoint) + val(attendancepoint) + val(nspoint) + val(foidpoint) + val(otherpoint)>

<cfif gradepoint GTE -20.45 AND gradepoint LTE 11.1>

<cfset maingrade = "F">

</cfif>

Votes

Translate

Translate

Report

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 ,
Dec 10, 2012 Dec 10, 2012

Copy link to clipboard

Copied

LATEST

Agreed.  I've never been a fan of using the hashmarks when not necessary.

To fix the issue, you need to cover all bases.  You provided only one conditional, but I'm assuming you have more.  But if the CF Server is throwing the error message "Variable undefined", then there is an open condition (or, more accurately, a lack of a default condition.)

<cfif gradepoint gte -20.45 AND gradepoint lte 11.1>

  <cfset maingrade = "F">

<cfelseif gradepoint gt 11.1 AND gradepoint lte 41.1>

  <cfset maingrade = "D">

<cfelseif gradepoint gt 41.1 AND gradepoint lte 72.2>

       and so on, until

<cfelse>

  <cfset maingrade = "A">

</cfif>

^_^

Votes

Translate

Translate

Report

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
Documentation