beginner: problem with operator "+"

G

Guest

greetings

im having problem with adding to values in as
the sample code : <% = Request("Travelling") + Request("Photographs") %

Let say travelling is 3 and photographs is 4, i get the answer 34
Please guide. tq in advance

** anyhow the same code works fine for all the other operators like "-" , "/" . "*" and so on
 
J

Juan Romero

The + sign is concatenating the values together because it takes them as
strings.
Convert them to integers using cint(Value), and try to avoid printing
results like that. Always assign them to a variable.

Good Luck.
 
K

Kevin Spencer

First, turn option explicit ON!!! Part of your problem is that you don't
seem to understand data types. All data in the Request is text. After all,
the Request message from the browser is pure text. Obviously, you can't add
the string "3" and the string "4" regardless of how numeric they may appear
to the human eye. They are text strings. In VB.Net, the "+" operator doubles
as both addition (for numbers) and concatenation (for strings). The run-time
compiler is smart enough to figure out whether you're dealing with strings
or numbers, and in this case, it is correct - they are strings.

By turning option explicit ON, you force yourself to strongly type all of
your variables, thus preventing a lot of similar mistakes, which may be hard
to track down when debugging.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top