Copy link to clipboard
Copied
Copy link to clipboard
Copied
>Obviously, ASP doesn't like the + sign...
This is not obvious to me. Why would ASP have a problem with the + ? What error are you getting?
Is the statement split to two or more lines? If so, you need to use the line continuation character '_'
So:
<%
Session("TotalBeforeTax")=(rsOrderHistory.Fields.Item("OrderSubTotal").Value) + _
(rsOrderHistory.Fields.Item("OrderShipping").Value)
%>
Copy link to clipboard
Copied
Say my OrderSubTotal is 589.8 and my OrderShipping is 59.9, I want it my session to be 649.7.
However, using the + sign, even the way you suggested, it will write: 589.859.9
In other words, in ASP, if you use the + sign between 2 recordset, it will display both:
Example:
(rsOrderHistory.Fields.Item("FirstName").Value) + (rsOrderHistory.Fields.Item("LastName").Value)
would display:
Joe Smith
I use thhe multiplication ( * ) and division ( / ) all the time, but for multiplication, not sure what to use...
Copy link to clipboard
Copied
OK, gotcha. The problem is that the values are being interpreted as string values. The + operator will concatenate the values if it interprets both as strings. A simple fix is to just convert them ( CDbl for example) in your expression. I gotta run now but write back if you have problems with this.
Copy link to clipboard
Copied
Hi Bregent,
I know you're probably busy but I'm really not familiar with CDbl...I don't understand because if I use any other operator is my Session, it works, it's just with the addition!
If I use:
<%
Session("TotalBeforeTax")= cStr(rsOrderHistory.Fields.Item("OrderSubTotal").Value) * cStr(rsOrderHistory.Fields.Item("OrderShipping").Value)
%>
or
<%
Session("TotalBeforeTax")= cStr(rsOrderHistory.Fields.Item("OrderSubTotal").Value) - cStr(rsOrderHistory.Fields.Item("OrderShipping").Value)
%>
It works like a charm...
Copy link to clipboard
Copied
The *, - and / operators are all mathematical operators. Because VBS is not a strongly typed language, it will perform math functions on strings when possible. The + operator is a bit different as it works as the addition operator on numeric values and the concatenate operator on strings. I guess they figured this was a good thing but experience has shown that it causes many more problems then it could ever solve.
So what you need to do is force the + operator to take the values as numeric using a convert function. In your example you are using a string convert function, which is exactly what you do not want. Use a numeric conversion. I choose Cdbl, but you need to use one most appropriate to your data:
<%
Session("TotalBeforeTax")= cDbl(rsOrderHistory.Fields.Item("OrderSubTotal").Value) cDbl(rsOrderHistory.Fields.Item("OrderShipping").Value)
%>
That should work.
Copy link to clipboard
Copied
So I need to use the conversion only on addition, or can I use it for the other operators as well. In other words, should I make the conversion a habit or just for additions on string values?
I just added the '+' sign in there and it works...I thought I tried this earlier when you seuggested the cDbl...maybe I had a syntax issue...works like a charm.
Thank you so much!
Copy link to clipboard
Copied
You're welcome.
You could use the convert functions with other operators but it is not necessary and I don't see any point of making a habit of it as a matter of convention. The other operators (-,*,/, etc) will implicitly convert strings to numbers if possible. If it is not possible (the string contains alpha chars for example), then the operation would fail, as would an explicit conversion. So I don't see any benefit.
Just remember to use the & operator when concatenating strings to avoid confusion that happens when using +.