Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weird comparison problem

Status
Not open for further replies.

mkyzar

Programmer
Joined
Oct 19, 2000
Messages
56
Location
US
This is really strange and hopefully someone can give me a suggestion. I have a form that the user fills out and a total is taken of 4 fields. The total of these fields are being compared to an amount field at the end of the form and if the total does not equal the amount field an error message is given and shows the values of the total and the amount fields. My problem is on one particular form the error messages says

"If the land code is 2 then the total cost must equal the amount. Total Cost: $304.59 Amount: $304.59"

As you can see, the amounts are the same and the error message shouldn't be happening. This hasn't happened any other time than when the user tries to enter this particular data into the form. Has anyone ever had this happen before or can someone suggest what may be the problem? All help is greatly appreciated.
 
What does the code look like? - tleish
 
Thanks for your help.

<cfif system eq &quot;CA&quot;>
<cfif form.vehcost eq &quot;&quot;>
<cfset vehcost=0>
<cfelse>
<cfset vehcost=#form.vehcost#>
</cfif>

<cfif form.equipcos eq &quot;&quot;>
<cfset equipcos=0>
<cfelse>
<cfset equipcos=#form.equipcos#>
</cfif>

<cfif form.laborcos eq &quot;&quot;>
<cfset laborcos=0>
<cfelse>
<cfset laborcos=#form.laborcos#>
</cfif>

<cfif form.othercos eq &quot;&quot;>
<cfset othercos=0>
<cfelse>
<cfset othercos=#form.othercos#>
</cfif>

<cfset totcost=#vehcost#+#equipcos#+#laborcos#+#othercos#>

<cfif isdefined(&quot;form.payrec&quot;) is &quot;yes&quot;>
<cfset temp=&quot;yes&quot;>
<cfelse>
<cfset temp=&quot;no&quot;>
</cfif>

<cfset error = false>
<cfset errmessage = arraynew(1)>

<cfquery name=&quot;findworkorno&quot; datasource=&quot;Rev02&quot;>
SELECT * from cabatch
WHERE cabatch.workorno = '#form.workorno#'
</cfquery>
<cfquery name=&quot;findworkorno2&quot; datasource=&quot;acctg&quot;>
SELECT * from crewmast
WHERE crewmast.workorno = '#form.workorno#'
</cfquery>

<!---1.---><cfif #form.service# neq 1>
<cfif #form.service# neq 3>
<cfif #form.service# neq 9>
<cfset error = true>
<cfset message = 'Service Code must be 1,3, or 9.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---2.---><cfif #form.landcode# neq 1>
<cfif #form.landcode# neq 2>
<cfif #form.landcode# neq 3>
<cfset error = true>
<cfset message = 'Land Code must be 1,2, or 3.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---3.---><cfif findworkorno.recordcount neq 0>
<cfset error = true>
<cfset message = 'This workorder number already exists in the batch file.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---4.---><cfif findworkorno2.recordcount neq 0>
<cfset error = true>
<cfset message = 'This work order number already exists in the master file.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<!---5.---><cfif isDefined(&quot;form.twn&quot;) is &quot;Yes&quot;>
<cfif form.twn neq &quot;&quot;>
<cfif right('#ucase(form.twn)#',1) neq 'N'>
<cfif right('#ucase(form.twn)#',1) neq 'S'>
<cfset error = true>
<cfset message = 'Township must end in either &quot;N&quot; or &quot;S&quot;'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---6.---><cfif isDefined(&quot;form.range&quot;) is &quot;Yes&quot;>
<cfif form.range neq &quot;&quot;>
<cfif right('#form.range#',1) neq 'W'>
<cfif right('#form.range#',1) neq 'E'>
<cfset error = true>
<cfset message = 'Range must end in either &quot;W&quot; or &quot;E&quot;'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<cfquery name=&quot;getzip&quot; datasource=&quot;tables&quot;>
SELECT * from zipcode
WHERE zip = '#form.zip#'
</cfquery>

<!---7.---><cfif getzip.recordcount lt 1>
<cfset error = true>
<cfset message = 'Zip Code is invalid.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---8.---><cfif '#form.jobcode#' gte '82' AND '#form.landcode#' eq '1'>
<cfset error = true>
<cfset message = 'If the job code is 82 or higher, the land code cannot be 1'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---9.---><cfif isDefined(&quot;form.miles&quot;) is &quot;Yes&quot;>
<cfif form.miles neq &quot;&quot;>
<cfif right(#form.miles#,2) neq '00'>
<cfif right(#form.miles#,2) neq '25'>
<cfif right(#form.miles#,2) neq '50'>
<cfif right(#form.miles#,2) neq '75'>
<cfset error = true>
<cfset message = 'Miles are reported in 1/4 mile increments.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---10.---><cfif isDefined(&quot;form.laborhr&quot;) is &quot;Yes&quot;>
<cfif form.laborhr neq &quot;&quot;>
<cfif right(#form.laborhr#,2) neq '00'>
<cfif right(form.laborhr,2) neq '50'>
<cfset error = true>
<cfset message = 'Labor hours are reported in 1/2 hour increments.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---11.---><cfif #totcost# neq #form.price#>
<cfset error = true>
<cfset message = 'If land code is 2 then Amount must be the same as actual cost. <b>Total Cost:</b> #dollarformat(totcost)# <b>Amount:</b> #dollarformat(form.price)#'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>


<!---12.---><cfif '#form.landcode#' eq '3' AND #totcost# neq #form.price#>
<cfset error = true>
<cfset message = 'If land code is 3 then Amount must be the same as actual cost. <b>Total Cost:</b> #dollarformat(totcost)# <b>Amount:</b> #dollarformat(form.price)#'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>

<!---13.---><cfif #form.acres# neq &quot;&quot;>
<cfif #form.miles# neq &quot;&quot;>
<cfset error = true>
<cfset message = 'Both Acres and Miles cannot be present in a record. It must be Acres OR Miles.'>
<cfset arrayappend(errmessage,&quot;#message#&quot;)>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>
<cfelse>
<cfset arrayappend(errmessage,&quot; &quot;)>
</cfif>


<cfif error eq true>
<cfoutput>Errors-Please hit <i>Back</i> on your browser to correct.
<ul>
<cfif errmessage[1] neq &quot; &quot;><li>#errmessage[1]#<p></cfif>
<cfif errmessage[2] neq &quot; &quot;><li>#errmessage[2]#<p></cfif>
<cfif errmessage[3] neq &quot; &quot;><li>#errmessage[3]#<p></cfif>
<cfif errmessage[4] neq &quot; &quot;><li>#errmessage[4]#<p></cfif>
<cfif errmessage[5] neq &quot; &quot;><li>#errmessage[5]#<p></cfif>
<cfif errmessage[6] neq &quot; &quot;><li>#errmessage[6]#<p></cfif>
<cfif errmessage[7] neq &quot; &quot;><li>#errmessage[7]#<p></cfif>
<cfif errmessage[8] neq &quot; &quot;><li>#errmessage[8]#<p></cfif>
<cfif errmessage[9] neq &quot; &quot;><li>#errmessage[9]#<p></cfif>
<cfif errmessage[10] neq &quot; &quot;><li>#errmessage[10]#<p></cfif>
<cfif errmessage[11] neq &quot; &quot;><li>#errmessage[11]#<p></cfif>
<cfif errmessage[12] neq &quot; &quot;><li>#errmessage[12]#<p></cfif>
<cfif errmessage[13] neq &quot; &quot;><li>#errmessage[13]#<p></cfif>
</ul>
</cfoutput>
</cfif>
 
I figured it out. It was a formatting problem. It was rounding my numbers off behind the scenes. Thanks for your help.

mkyzar
 
Just for grins, try taking out the DollarFormat and see what the raw values are. Could one of the values have a trailing space or something in it?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top