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!

Totalling variables

Status
Not open for further replies.

Shilohcity

Technical User
Jul 12, 2000
136
GB
Hi there

I am still working my way through this seemingly straight forward problem....

I have a page which passes variables related to price and quantity to an asp page which display a proxy order for confirmation with subtotals and total price. So far I have produced a sub total

subtotal = Request("quantity") * Request("price")

This produces subtotal price for each item but I am having trouble getting the total of all the subtotal prices.

Any suggestions would be most welcome.

 
I'm not sure I understand exactly where the hangup is. Put your ASP page up and maybe we can better help you.

Wushutwist
 
As you loop through the lidt of variables put in another variable like this

subtotal = Request("quantity") * Request("price")

total = total + subtotal

this wiil give you the total at the end

Mark
 
I dont have the code with me at present but will post it later today. In the meantime I will try to explain the problem a bit more clearly.

At present all of my subtotal variables have the same name "subtotal" which means I cant add them together so if I give them a unique id using

subtotal = Request(“price”) * Request(“quantity”)

count = 0
Do while count =< Request(&quot;Records&quot;)'total items ordered/passed from order form
subtotal = count &amp; subtotal
count + 1
Loop

So now I have 1subtotal, 2subtotal etc. but how do I total them? All I can think of is this but I know it wont work.

Total = 1subtotal + 2subtotal + 3subtotal etc.

Hope this clears things up a little.

Justin.
 
Use an array to store the subtotals.
Therefore subtotal number one would be in subtotal[0] ... etc.

The loop through the subtotal array to get total.

INCOMPLETE EXAMPLE
Code:
' Declare Dynamic Array
Dim subtotal()
Dim total
Dim counter

' Set Upper Bound to # of Records
Redim subtotal(Request(&quot;Records&quot;)-1) 

'
' Do the subtotal stuff here
'

' Array index starts at 0
counter = 0

' Initialize total to 0
total = 0

Do While (counter <= UBound(subtotal))
   total = total + subtotal(counter)
   counter = counter + 1 'increment index
End Loop
Hope this helps.
Wushutwist
 
Thank you both for your help.

I think I was trying to complicate the process more than I needed to. I had the idea in my head of what needed to be done and was very close all I was missing was the &quot;total = total + subtotal&quot; line.

Thanks again

Justin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top