PDA

View Full Version : adding variables


Keltoi
08-18-2003, 11:04 AM
I feel a bit stupid asking this, but how do you add two variables together?
This is what I have:

varSL = Request.Form("sl")
varQty = Request.Form("qty")
varSL = varSL + varQty

However, say both form variables contain '5' I end up with '55' instead of
'10'

Any help much appreciated

raf
08-18-2003, 11:27 AM
if you post a form, then all variable-values are concidered to be strings.
So you need explicitely convert them. Like

varSL = CInt(Request.Form("sl")) + CInt(Request.Form("qty"))

(if you only expect integers. CDbl for instance if you expect floats)

Keltoi
08-18-2003, 11:37 AM
Thanks raf, I knew it would be simple... and indeed I knew it as soon as I saw it :rolleyes:

Quick question though if I mayCDbl for instance if you expect floats What are 'floats'?

raf
08-18-2003, 11:55 AM
i don't know if it is commonly used in VBscript terminologie, but 'floats' comes from floating-point numbers --> numbers like 34.45 or 34,45 depending on your reginal settings decimal symbol

If you expect such values, then you shouldn(t use CInt as it will round the value to the nearest even number so you'll get incorrect results.

Keltoi
08-18-2003, 12:00 PM
That's useful to know, Thanks :thumbsup: