473,322 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

beginner: problem with operator "+"

me2
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
Nov 18 '05 #1
2 1078
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.

"me2" <an*******@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
greetings,

im having problem with adding to values in asp
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.

Nov 18 '05 #2
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.

"me2" <an*******@discussions.microsoft.com> wrote in message
news:4B**********************************@microsof t.com...
greetings,

im having problem with adding to values in asp
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.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Quentin Crain | last post by:
Hello All! Could someone explain (links are good too!) why: >>> 1+"1" Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unsupported operand types for +: 'int' and...
6
by: Christian Brechbühler | last post by:
The template std::valarray behaves pretty much like a mathematical vector. Arithmetic operators apply elementwise. Now I'd like to extend this to a user-defined type, e.g., complex. ...
8
by: Douglas | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, The following code does not compile if line 3 is uncommented "using namespace std". I do not understand it. Could...
6
by: Guagua | last post by:
I have lots of expression like "a <?= b" in my original code. However I switch to another compiler from gcc that doesn't support operator "<?=". How could I define the operator so that the...
2
by: NewToCPP | last post by:
I have the following code. It complains that there is Possible use of null pointer. How to handle "operator " returning reference to the null pointer? class my_data { private: my_period*...
8
by: av | last post by:
i have my little string class, now i want do define something like this but for doing it i have to write sstream& operator+(char* a, char* b){} but compiler say something like...
10
by: lovecreatesbea... | last post by:
Is it correct and safe to compare a string object with "", a pair of quotation marks quoted empty string?If the string object: s = ""; does s contain a single '\'? Is it better to use...
1
by: Sunny | last post by:
The way to overload operator << is : ostream& operator << (ostream& os, const Obj& obj); and this is a member function. My question is why do we need to provide a const reference of Obj as...
7
by: Bill Davy | last post by:
I want to be able to write (const char*)v where v is an item of type Class::ToolTypeT where ToolTypeT is an enumeration and I've tried everything that looks sensible. There's an ugly solution, but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.