Solved

Adding two numbes together

Posted on 2014-12-19
4
63 Views
Last Modified: 2014-12-19
Hi,


I am trying to add my numbers together but nothing is working my logic as always is off.  

specially around the holidays.  

So, I need your help please!!!


<cfoutput query="FiveYearPlan"> 
            <cfset CostPlan = #replace(FiveYearPlan.MajorUpgradeCost,"<","&lt;")#>
            <cfset variables.CostPlanFrom = 0>
			
	<cfif #CostPlan# neq ''>
				<cfswitch expression="#CostPlan#">
 				<cfcase value="&lt;$100K">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 0>
                    0
 				</cfcase>
 				<cfcase value="$100K to $500K">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 100>
                    100
 				</cfcase>
 				<cfcase value="$500K to $1M">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 500>
 					500
 				</cfcase>
 				<cfcase value="$1M to $5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 1000000>
 					1000000
 				</cfcase> 
                <cfcase value=">$5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 5000000>
 					5000000
 				</cfcase>
                </cfswitch> 
           <cfelse>
           &nbsp;
           </cfif>
</cfoutput>		


<!--- variables.CostPlanFrom is not adding up ---> 
<!--- What am I doing wrong? ---> 

<cfoutput>#variables.CostPlanFrom#</cfoutput>  

Open in new window

0
Comment
Question by:lulu50
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 40509529
lol,  especially around the holidays!

I'm thinking that some of your switch cases are not matching.
Let's find out which ones by using the defaultcase...

<cfoutput query="FiveYearPlan"> 
            <cfset CostPlan = replace(FiveYearPlan.MajorUpgradeCost,"<","&lt;")>
            <cfset variables.CostPlanFrom = 0>
			
          	<cfif #CostPlan# neq ''>
				<cfswitch expression="#CostPlan#">
 				<cfcase value="&lt;$100K">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 0>
                    0
 				</cfcase>
 				<cfcase value="$100K to $500K">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 100>
                    100
 				</cfcase>
 				<cfcase value="$500K to $1M">
                	<cfset variables.CostPlanFrom = variables.CostPlanFrom + 500>
 					500
 				</cfcase>
 				<cfcase value="$1M to $5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 1000000>
 					1000000
 				</cfcase> 
                <cfcase value=">$5M">
                    <cfset variables.CostPlanFrom = variables.CostPlanFrom + 5000000>
 					5000000
 				</cfcase>
				<cfdefaultcase>
				   Could not match [#costPlan#]
				</cfdefaultcase>
                </cfswitch> 
           <cfelse>
              Empty CostPlan
           </cfif>
		   <br>
</cfoutput>		

Open in new window


If your query FiveYearPlan has an ID for each of the values, it might be better to use the ID in the cfswitch for an easier match.
0
 

Author Comment

by:lulu50
ID: 40509631
gdemaria I agree!!!!

having this defaultcase thing helps a lot specially around the holidays.  

I found the issue and fixed it thank you again.
0
 

Author Closing Comment

by:lulu50
ID: 40509632
Thank you
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40509665
ha, yes, I always like using defaultcase around the holidays to help spot little problems, like who did I forget to buy a present for! :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now