Skip to main content
Inspiring
December 10, 2012
Question

Variable undefined

  • December 10, 2012
  • 2 replies
  • 569 views

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>

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    December 10, 2012

    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>

    WolfShade
    Legend
    December 10, 2012

    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>

    ^_^

    WolfShade
    Legend
    December 10, 2012

    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.

    ^_^