Click to See Complete Forum and Search --> : Problem with ASP...
hello,
I am having problem and wondering if anyone can give me advices.
I am trying to calculate amount from data that I retrieve from DB, based on session of the login person.
I retrieve this data using while not, so It will display the data while rs NOT EOF. each of this data will have numeric value that I will have to multiply with the number of recordcount each data has
i.e.
data 1 has 10 members where each member values $1.00 therefore 10x$1.00 is $10.00 (subtotal). I managed to do this. But the problem is I need to calculate the whole lot (final total - add all of the sub totals), all the data displayed until EOF and it can be varied depends on the session.
Has someone ever countered smilar problem? Thanks heaps in advanced!
buntine
06-23-2005, 01:28 AM
You could use a dynamic array to store each subtotal and then calculate a grand total.
You need to redimenion the array for each subtotal. This can be a bit resource-hungry if you are working with a large application, but will not pose a problem to a smaller app.
ReDim Preserve arrVariableName(aNumericValue)
Do not forget the Preserve keyword as not using it will cause the data in the array to be overwritten after a redimension.
Regards.
Hi buntine,
Thanks heaps for replying!
I am trying to get hold what you're trying about.
The thing is I am displaying data from 2 tables, the data being EOF-ed is the data from table 1 (WHERE id = session id). If the data from table 1 come up with for example 6 records. Each of these 6 records should have another 6 data of categories, in which each category has value and result in subtotal.
So what I am really trying to have the final total of categories' subtotals. In 6 records should have 36 of data categories. and the rs EOF is only for the records whereas the categories only following the main data.
How do I array the data that I want? Can you be more specific if you dont mind? Thank you so much.
buntine
06-23-2005, 01:55 AM
Create an array outside of your loop without specifying a size. Also create a variable to increment.
Dim arrSubTotals()
Dim intCount: intCount = 0
Then, within the EOF loop, you can access the further 6 categories of data, redimension the array and then insert the latest subtotal into it.
' Access the further data...
intCount = intCount + 1
ReDim Preserve arrSubTotals(intCount)
arrSubTotals(intCount) = yourSubTotalGoesHere
Then, after the loop, you can loop through the array and calculate the grand total.
Dim i, intTotal
intTotal = 0
For i = 0 To (Bound(arrSubTotals)
intTotal = intTotal + CInt(arrSubTotals(i))
Next
Response.Write ("Total: " & CStr(intTotal))
Here is a good article that explains the creation of a aynamic array object. It may be helpful: http://www.4guysfromrolla.com/webtech/032800-1.shtml
Regards.
Hi Buntine
Thanks heaps! You're the greatest! I really appreciate it...It's working well almost because some of the value of category of datas are $0.50 and the total value is less than it is supposed to be i.e supposedly $40 but printed there $39, supposedly $23.5 but printed $23
Dim i, intTotal
intTotal = 0
For i = 0 To (Bound(arrSubTotals)
intTotal = intTotal + CInt(arrSubTotals(i))
Next
Response.Write ("Total: " & CStr(intTotal))
and in here I put the Bound as UBound, you probs mistyped it. And if I changd 0 to 1, the total value would be more than its supposed to be i.e $23.50 becomes $24.. but it's working tho I need to work on it again.. do you have any other suggestions? I am looking up if I can make the intTotal decimal.
Thank heaps again! you rock!
buntine
06-23-2005, 03:08 AM
No worries. You can use CDbl(...), which will cast the variables as doubles (decimals) rather than flat integers.
Dim i, intTotal
intTotal = 0
For i = 0 To UBound(arrSubTotals)
intTotal = intTotal + CDbl(arrSubTotals(i))
Next
Response.Write ("Total: " & CStr(intTotal))
Try that.
Your right. I did misspell it. ;)
Regards.
u did it again buntine! Thanks heaps!.. I learnt alot from this :p ...thanks again!
warmest regards,
aout
buntine
06-23-2005, 04:09 AM
No worries. ;)