3 Replies Latest reply on Dec 10, 2012 11:52 AM by WolfShade

    Variable undefined

    College Kid Level 1

      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>

        • 1. Re: Variable undefined
          WolfShade Level 4

          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.

           

          ^_^

          • 2. Re: Variable undefined
            BKBK Adobe Community Professional & MVP

            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>

            • 3. Re: Variable undefined
              WolfShade Level 4

              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>

               

              ^_^