473,225 Members | 1,294 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,225 software developers and data experts.

Addition in ASP

Jay
I have two strings that instead of adding them together to get the sum the
are concatenating together. Does anyone know how I can get these two to
add.

while not rstemp4.eof
vservdate = rstemp4("servdate")
vdesc = rstemp4("desc")
vservhours2 = rstemp4("servhours")
vtravelhours = rstemp4("travelhours")
vtech = rstemp4("tech")
shvar = shvar + rstemp4("servhours")
thvar = thvar + rstemp4("travelhours")

rstemp4.movenext
wend
Jul 19 '05 #1
3 5199
shvar=shvar+cint(rstemp4("servhours"))

assuming, of course that servhours only contains numbers (no strings or
nulls)

"Jay" <jl****@optonline.net> wrote in message
news:FT***********************@news4.srv.hcvlny.cv .net...
I have two strings that instead of adding them together to get the sum the
are concatenating together. Does anyone know how I can get these two to
add.

while not rstemp4.eof
vservdate = rstemp4("servdate")
vdesc = rstemp4("desc")
vservhours2 = rstemp4("servhours")
vtravelhours = rstemp4("travelhours")
vtech = rstemp4("tech")
shvar = shvar + rstemp4("servhours")
thvar = thvar + rstemp4("travelhours")

rstemp4.movenext
wend

Jul 19 '05 #2

I thought it was kinda buggy the other day in my code ... I had

<%
'// string becaused passed from the datasource as such
firstNum = "1"
secondNum = "1.5"

firstNum = FormatNumber(firstNum, 1)
secondNum = FormatNumber(secondNum, 1)

total = firstNum + secondNum
%>

total was equalling 11.5 ... the strings combined

so I changed to this, and it worked

total = 0 + firstNum + secondNum

I don't know if it is because it understood to use addition because I
had the number 0 there ... that's my only guess ... I would like to
hear more on this anyone

Brynn


On Sat, 10 Jan 2004 21:11:01 GMT, "Jay" <jl****@optonline.net> wrote:
I have two strings that instead of adding them together to get the sum the
are concatenating together. Does anyone know how I can get these two to
add.

while not rstemp4.eof
vservdate = rstemp4("servdate")
vdesc = rstemp4("desc")
vservhours2 = rstemp4("servhours")
vtravelhours = rstemp4("travelhours")
vtech = rstemp4("tech")
shvar = shvar + rstemp4("servhours")
thvar = thvar + rstemp4("travelhours")

rstemp4.movenext
wend


Jul 19 '05 #3
All types are variants in VBScript. There is a concept called data type
precedence which matches types together (sort of like a lowest common
denominator) if the engine has no idea what you *meant* the types to be.

Add to this that we have a multi-purpose operator (many people use addition
+ for string concatenation as well).

So, to make sure numbers are treated as numbers, cast them explicitly using
CInt, CLng, CDbl. Formatnumber keeps them as a string, so this doesn't help
any.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Brynn" <z@z.com> wrote in message
news:40**************@news.comcast.giganews.com...

I thought it was kinda buggy the other day in my code ... I had

<%
'// string becaused passed from the datasource as such
firstNum = "1"
secondNum = "1.5"

firstNum = FormatNumber(firstNum, 1)
secondNum = FormatNumber(secondNum, 1)

total = firstNum + secondNum
%>

total was equalling 11.5 ... the strings combined

so I changed to this, and it worked

total = 0 + firstNum + secondNum

I don't know if it is because it understood to use addition because I
had the number 0 there ... that's my only guess ... I would like to
hear more on this anyone

Brynn


On Sat, 10 Jan 2004 21:11:01 GMT, "Jay" <jl****@optonline.net> wrote:
I have two strings that instead of adding them together to get the sum theare concatenating together. Does anyone know how I can get these two to
add.

while not rstemp4.eof
vservdate = rstemp4("servdate")
vdesc = rstemp4("desc")
vservhours2 = rstemp4("servhours")
vtravelhours = rstemp4("travelhours")
vtech = rstemp4("tech")
shvar = shvar + rstemp4("servhours")
thvar = thvar + rstemp4("travelhours")

rstemp4.movenext
wend

Jul 19 '05 #4

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

Similar topics

3
by: Mark Dickinson | last post by:
Can anyone either reproduce or explain the following apparently inconsistent behaviours of __add__ and __mul__? The class Gaussian provides a sub-bare-bones implementation of Gaussian integers (a...
7
by: jeffbernstein | last post by:
Greetings. I'm reading "How to think like a computer scientist: Learning with Python" and there's a question regarding string operations. The question is, "Can you think of a property that...
2
by: akickdoe22 | last post by:
i could really use help finishing this addition program. I'm stuck on the part that allows you to add any two large integers,up to 100 digits,(pos+pos, neg+neg, and pos+neg). could use hints ideas...
24
by: Alex Vinokur | last post by:
Consider the following statement: n+i, where i = 1 or 0. Is there more fast method for computing n+i than direct computing that sum? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
3
by: snow.carriers | last post by:
Let me first state that I'm using Borland Turbo C++, it's relatively old so the new string methods won't work. Anyways, first I'm trying to collect a line of a string (with numbers, letters,...
5
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express...
5
by: Paul | last post by:
Why is the addition here adding the number as a string but the subtraction works fine? function boxchange(box) { iv= dbform.ut.value if (box.checked == true) { iv = iv - box.value } else {...
3
by: srinivas33034 | last post by:
Hi there, my problem is i have to perform addition dyamically My req is i have 3 txt boxes.. and another text box to display total additon.. as i am entering the values in TextBox1 i want...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.