Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maths sum giving me problems 2

Status
Not open for further replies.

krappleby025

Programmer
Sep 6, 2001
347
NL
hi all i have a simple script that is supposed to add, two numbers together, one is a database number and the other is a form input number, but its not working, if the database is set at 50 and the form sends 8 then the result ends up being 508 or 805 and not 58 like it should be,

funny thing is i am using the + sign

take a look

amountadd = request.form("amount")
Set con = server.Createobject( "ADODB.Connection" )
con.open = ""
set query = con.execute("SELECT amount FROM money where idnum=1")
oldamount = query("amount")
totalamount = amountadd + oldamount
%>
new amount is = <% =totalamount %>

would like your comments

thanks
 
Try using:

totalamount = cint(amountadd) + cint(oldamount)


see what that gives you...

mwa
 
When you use the + in VBScript the second value is converted to the same data type of the first if possible.

Since VBScript is not strong typed, your line of code amountadd = request.form(&quot;amount&quot;) creates amountadd as a string.

Your line of code &quot;totalamount = amountadd + oldamount&quot; converts oldamount to a string and concatenates it to amountadd.

Hope this helps you understand what is going on.

Thanks,

Gabe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top