Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding two numbes together

Posted on 2014-12-19
4
Medium Priority
?
70 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 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