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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

won't add up the values, will only concatenate help! 1

Status
Not open for further replies.

bikebanditcom

Programmer
Jun 11, 2003
117
US
won't add up the values, will only concatenate please help. the following bit of code is one of many in an if..then statement but it only concatenates them. how can i get around this?

".....ElseIf custRestockingFee = "Yes" And california = "Yes" And complete = "Yes" And CrdtToBeIssd = "Yes" Then
restockingFee = mercValue * .2
transAmount = (mercValue) + (addRtrnShipping) + (addOrigShipping) + (caSalesTax) - (restockCalc)
transType = "Enter Credit"....."

i've tried getting rid of the parenthesis or adding more in around the entire thing but no such luck. help please.
 
You don't need the brackets around your variable names. If it is still concatenating your results, then make sure all of the variables are numeric, if it they are strings then '+' may be interpreted as a concatenation operator instead of addition.

Mitch


What happens if you get scared half to death twice?
 
Try forcing the issue with CCur(YourVariable) or CDbl(YourVariable) before you attempt to perform any math on them.
 
how do i do this veep? where do i put that bit of code? i tried putting CDbl before every variable like this

...ElseIf custRestockingFee = "No" And california = "No" And complete = "Yes" Then
restockingFee = 0
transAmount = CDbl(mercValue) + CDbl(AddOrigShipping) + CDbl(AddRtrnShipping)
transType = "Enter Credit"...
 
That should work but I usually do it as soon as I assign a value to my variable like:

If request.form(&quot;mercValue&quot;) <> &quot;&quot; then
mercValue = CDbl(request.form(&quot;mercValue&quot;))
ELSE
mercValue = 0 ' or whatever else you want it to be
End if

Also, you'll find out then and there whether or not the variant can be converted because it will throw a type mismatch error if it can't.

 
thanks so much that fixed it. i declared it at the variable. Thanks

Dan
 
Data read in on an ASP page from request.form() or request.querystring() will by default be in string format. Attempting to add using &quot;+&quot; will concatenate them, though really ASP's VBScript documentation wants you to use &quot;&&quot; instead for string concatenation. Another way besides the cDbl() funtion mentioned above is to add &quot;0+&quot; to the number being fetched, added, substracted, etc.

nTot=0+xVal1+xVal2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top