Forum Moderators: open

Message Too Old, No Replies

ASP or VB Operaters for Addition etc...++

         

powerslave

2:22 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



I noticed if u add 3+5 in my ASP im getting 35 and not 8

Could someone please tell me what I need to do for a simple addition? Any other operator information or a link to somewhere would be handy too :)

Ive tried with or without (Brackets)

Thanks

defanjos

2:31 pm on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<%
dim test
test = 3 + 5
response.write test
%>

You get 8

<%
dim test
test = "3" + "5"
response.write test
%>

You get 35

txbakers

2:46 pm on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



to elaborate on the above post - if the addends are strings (or even if the first one is a string) you will concatenate rather than "add".

To be sure you are adding, you can use the "cint" (for integers) function in VB as follows:

dim test
test = cint("5") + cint("8")
test = 13

there are lots of ways to do this, but the goal is to make sure you are adding numbers, rather than strings.

powerslave

11:40 am on Apr 27, 2005 (gmt 0)

10+ Year Member



test = 3 + 5
or
test = (3 + 5)

gave me 35 both times, not 8.

ill try the cint thanks :)

mrMister

11:48 am on May 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



powerslave, what you're experiencincing is typical of the type of problems that programmers get with loose typing and late binding.

Make sure you set Option Explicit and Option Strict to your pages, it'll save you all sorts of headaches further down the road. Your code will run faster as well.