Skip to main content
Participating Frequently
August 20, 2010
Question

Val Help, Please

  • August 20, 2010
  • 2 replies
  • 819 views

So I have this code that reads in a CSV file which contains a student's grades for an exam.  Usually, the grades are numeric (obviously), but on occasion, there will be outstanding circumstances that will result in the grade having an asterisk appended to it (95*, for example). So in the program that reads in the grades, I need to convert the datatype of the grade variable to a numeric before entering the info in my database.

All well and good, but for some reason the code I have isn't working.  Currently the code in question looks like this (cfabort used for testing):

<cfset grade = Val('grade')>
#grade#
<cfabort>

Unfortunately, the output that is being generated is the grade with the asterisk still attached as opposed to the numeric value only. Am I incorrectly using cfset?  What is the issue?  Thanks in advance for your help!

    This topic has been closed for replies.

    2 replies

    skythrockAuthor
    Participating Frequently
    August 20, 2010

    Thanks all, the querysetcell worked!

    Inspiring
    August 20, 2010

    I am glad you got things sorted out.

    BTW: I am not loving this forum software. It loves to mangle email posts.

    Inspiring
    August 20, 2010

    I'm having a hard time believing that val('grade') is not returning zero.  What you want is

         <cfset grade=val(grade)>

    The quotes are telling the val() function to turn the literal string 'grade' into a numeric, which should end up being zero.

    Another approace would be:

         <cfset grade="replace(grade,"*","","ALL")>

    -reed

    skythrockAuthor
    Participating Frequently
    August 20, 2010

    Tried both suggestions, Reed, but neither of them worked. The output still has the asterisk appended.

    Inspiring
    August 20, 2010

    I am with Reed on this one. I see no reason it should not work. Unless something else is going on elsewhere in the code, that we cannot see.

    Can you post a small example (with values) that reproduces the issue?