Skip to main content
Known Participant
July 5, 2006
Question

cfscript

  • July 5, 2006
  • 3 replies
  • 578 views
I'm just trying to get this function to compile and get this error message:
ColdFusion was looking at the following text: \"
Invalid CFML construct found on line...col...

This function looks okay to me based on what I've read in the documentation. I'm not sure how I should reference the form variables, though. CF might require "#form.name#" , #form.name#, or form.name and I'm not familiar with when it requires one or the other.
Is there anything wrong with what I've written?
------------------------------------------------------------------------
<cfscript>
function lcost("form2.DUP")
{var total = 0;
if ( form2.DUP ="yes")
total= form2.COPIES *(form2.ORIG/2)* paperlist.single_side;
return total;
}
</cfscript>
This topic has been closed for replies.

3 replies

Inspiring
July 5, 2006
> local variable must be initialized

OK. What does this error message *say*?

> {var total;

And what are you *not* doing here?


> if ( form2.DUP eq "yes")
> tot= form2.COPIES *(form2.ORIG/2)* paperlist.single_side;

You're also using the wrong variable name here.

Plus you're using a whole bunch of variables that - I can only guess -
exist in the calling code.

You should really pass any data you intend to use IN to a function. Not
just hope it's already there.

--
Adam
Deb3Author
Known Participant
July 5, 2006
No. I changed "=" to EQ and changed the function reference from "form2.DUP" to function lcost(DUP) and moved to the next compile error:
local variable must be initialized

<cfscript>

function lcost(DUP)
{var total;
if ( form2.DUP eq "yes")
tot= form2.COPIES *(form2.ORIG/2)* paperlist.single_side;
return total;
}
</cfscript>
Inspiring
July 5, 2006
See if this works:

<cfscript>
function lcost("form2.DUP") {
var total = 0;
if ( form2.DUP EQ "yes") {
total= form2.COPIES *(form2.ORIG/2)* paperlist.single_side;
}
return total;
}
</cfscript>
BKBK
Community Expert
Community Expert
July 6, 2006
Use the so-called black-box principle. It is a basic rule in object-oriented programming that ensures your code will be reusable. Not only you, but everybody else, should be able to call your function.

I make out 4 variables, and would therefore suggest the function code below. Your particular call will be:

<cfset myTotal = lcost(form2.DUP, form2.COPIES, form2.ORIG, paperlist.single_side)>