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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of text boxes

Status
Not open for further replies.

benniesanders

Programmer
Jan 20, 2002
199
US
Hi There,

I have a group of text boxes named p1 through p14. The results are submitted to a form where they need to be added up. Is there a quicker, better way to add them up instead of doing:

request("p1") + request("p2") , etc. through "p14"?

Thanks a million for your thoughts!
 
yes try using a do loop or for loop action in your script ie something like

for e=1 to 14

then in your next line add your request something like

request.form(e)

then add the results together

total = total + request.form(e)

then add one to the initial loop and return it

e=e + 1

loop


I do not think that is exactly how to word it but it is an idea

and you produce your total using

total

hope that helps
 
Thanks, k. It would work great but I also have quantity boxes q1-q14, so it picks that up too. If I do p1-p14 it says subscrpt out of range. How do I specify request.form("p1") through ("p14"). Thanks a million!
 
Hi,

Try this:
Code:
<%
For i = 1 To 14
  strValue = CInt(Request.Form(&quot;p&quot; & i))
  strTotal = strTotal + strValue
Next
%>
Tony
reddot.gif WIDTH=300 HEIGHT=2 VSPACE=3

 
Hi Tony,

I'm getting this error:

Type mismatch: 'cint'

I suspect it's coming over as a string. How do I convert it?
 
Hi Tony,

I'm getting this error:

Type mismatch: 'cint'

I suspect it's coming over as a string. How do I convert it? Thanks!
 
I use CInt to force my Querystring variables to an integer for comparison reasons. This will fail though if they are not present. Are you getting P1 to p14 as querystrings EVERY time?? If not then you will need to modify that code slightely Tony
reddot.gif WIDTH=300 HEIGHT=2 VSPACE=3

 
I'm not sure what you mean. The user may only fill out P1, or P2, or P10. Not all of them will ever be present at once. When I do a response write on strTotal, and the values have come over as 35 and 50, it will write: 3585 within the for next statement, then the error. If I remove the cint of course it writes 3550. If I response write out of the for next statement, it gives me nothing when I leave in the cint.

 
That did it. Thanks so very much for your help. This will save a lot of time and reduce errors. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top