How to view to total of some calculated values?

# Thread: How to view to total of some calculated values?

1. Junior Member
Join Date
Dec 1969
Posts
19

## How to view to total of some calculated values?

Hello there! Here&#039;s the thing. I am busy learning ASP, and I must say I am impressed by all the things you can do with it! At this moment, I am trying to make a little website using ASP, where I can insert records in a table, with rows containing information like:<BR>1) ID; <BR>2) Price of item;<BR>3) VAT (percentage);<BR>4) Number of items.<BR><BR>Now I want to be able to create a dynamic page, viewing the from the table. Of course, no problem to do so with one certain record. But now I want to display some information about several records (selected by date or ID or whatever). Again, not a problem to display columns 1 to 4 for several rows (I am using Dreamweaver MX, using repeating region). But now comes the problem. I want to do some calculations with the information. So in the dynamic table, I want to display the total VAT as an amount of money. Let&#039;s say that ID 4 has ordered 15 items of a certain product for \$ 10 (excl. VAT) per product. The VAT is 20%. Now I want to display:<BR><BR>ID = 4; Price = 10; VAT = 20; NumberOfItems = 15; TotalVAT = 30. <BR><BR>I insert the TotalVAT value in the dynamic table by using a ASP command like &#060;% TotalVAT = (VAT/100)*NumberOfItems*Price %&#062;&#060;%= TotalVAT %&#062; to display the new TotalVAT column. I insert this new column in the repeating region, and voilĂ*: the TotalVAT is displayed for all the ID&#039;s requested. BUT, I want to add all these values and display the total. How can I do that?? <BR><BR>It may be very simple (or impossible), but I could not find out how to display this total. Can anybody help me?<BR><BR>Thanks!<BR><BR>Paul

2. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: How to view to total of some calculated values

Im not familliar with Dreamweaver MX but this should help.<BR><BR>Make another variable to keep track of the totals.<BR>Give it a value "outside" your repeater to start with.<BR><BR>intMyTotal = "0"<BR><BR>&#039;Repeater Start<BR>intMyTotal = (intMyTotal + TotalVAT)<BR>&#039;Repeater end<BR><BR>&#060;%=intMyTotal%&#062; is a Grand Total of all your TotalVAT&#039;s<BR><BR>Should help you somewhat.<BR>Russell M

3. Junior Member
Join Date
Dec 1969
Posts
19

## RE: How to view the total of some calculated value

Thanks Russell! I will try this! <BR><BR>Paul

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## A MAJOR BUG IN THAT!

[hl="yellow"]intMyTotal = "0" [/hl]<BR><BR>NO NO NO!<BR><BR>That makes the intMyTotal variable a *string*.<BR><BR>And now, when you do<BR> inMyTotal + TotalVAT<BR>you will get something like the *STRING*<BR> 07.359.332.33<BR>as the result, as each new value is APPENDED to the STRING!<BR><BR>The + operator, when used with a string, does string concatenation, *NOT* addition!<BR><BR>So simply do<BR><BR> intMyTotal = 0<BR><BR>************<BR><BR>But I have to ask Russell: Why would you assume it will be an INTEGER??? Tax is usally done in pounds and pence (dollars and cents), so it&#039;s NOT an integer value.<BR><BR>If you must use hokey Hungarian notation, please use the right notation. In this case, maybe<BR> currMyTotal = 0.0<BR>??? (curr for currency?) or perhaps<BR> dblMyTotal = 0.0 <BR>??? (dbl for double).<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: A MAJOR BUG IN THAT!

Prolly was a typo "0", i dont normally do it.<BR><BR>Yes he said he was learning so should have taken more care.<BR><BR>I didn&#039;t presume it was an integer<BR>I presumed it was not a Currency field since he gave eg: of<BR>ID = 4; Price = 10; VAT = 20; NumberOfItems = 15; TotalVAT = 30<BR><BR>Since he has already performed calculations and has come up with some kind of numerical value. (Not dollers and cents until formated)<BR><BR>If his TotalVat was say 30.2948 and you ad that to 0 or 0.0<BR>you still get 30.2948 either way.<BR><BR>You are right tho 0.0 and dbl is the Proper way.<BR><BR>I know it was wrong, but just to add that in this case it still would have worked if he didnt pick it up, vbs is smart enough to figure out that<BR><BR>Dim intST, intTS<BR>intST = "5"<BR>intTS = 10<BR>intTest = (intST + intTS)<BR>intTest produces 15<BR><BR>So long as one is an integer of some sorts...<BR>If both were strings then yes 510<BR><BR>Even for a Typo, in this case still would have worked...<BR><BR>Wouldn&#039;t get away with it in .net tho<BR><BR>Was just a quick idea i gave to stear him in a direction.<BR><BR>Sorry for causing so much grief.<BR><BR>Russell M

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## My mistake! I owe you one.

Though this is truly bizarre, because in various other cases we have had to fix similar problems by doing CDBL(...the string...).<BR><BR>But I couldn&#039;t make it fail even though I did<BR> num = " 0 " &#039; space before and after<BR><BR>So now I will have to reexamine various chunks of code, to see what the rule *really* is!<BR><BR>It&#039;s especially weird because if you *compare* a string vs. a number the number gets converted to a string! Example:<BR>&#060;%<BR>s = "0"<BR>n = 0<BR>If s = n Then Response.Write "same" Else Response.Write "different"<BR>%&#062;<BR>And, yes, you will get "different"!<BR><BR>So you have indeed found a peculiarity of VBS and exploited it.<BR><BR>And this is a *very* minor point, but:<BR><BR>&#060;% TotalVAT = (VAT/100)*NumberOfItems*Price %&#062;<BR><BR>That is, VAT is a percentage, which he divides by 100 to get the decimal fraction and then multiplies that, etc. So with <BR> VAT=20, NumberOfItems=10, Price=15<BR>indeed TotalVAT will be 30, an integer. But just make Price be 14.99 and it isn&#039;t. He just *happened* to pick an example where it came out as an integer, so no wonder you chose intXXX.<BR><BR>Anyway, sorry about the "0" thing. I still wouldn&#039;t do it, but you are correct in saying it is *NOT* an error.<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
6,476

## For sure, care to see just

how weird it gets, just cause im bored? hehehe<BR><BR>Your right you can not do comparisson to them... never work..<BR>And lets call it Bad Programming & Practice...<BR>But like i said it was a typo.<BR><BR>But here, see just how weird it does get.<BR><BR>&#060;%<BR>Dim intST, items, stringPrice, Vat, TotalVat, strAdd<BR>strAdd = "200"<BR>Vat = "4"<BR>items = "4"<BR>stringPrice = "60.677864"<BR>intST = "100"<BR><BR>TotalVAT = (VAT/intST)*Items*stringPrice<BR>Response.Write FormatCurrency(TotalVAT + strAdd)<BR>Response.Write "<BR>" & (Now() + Vat)<BR><BR>%&#062;<BR><BR>Now go figure that one...<BR><BR>Russell M

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oh, that one I expected!

See this FAQ:<BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=189<BR><BR>Just as, apparently, numbers have precedence over string when doing an addition operation, so do dates have precedence over numbers.<BR><BR>That&#039;s why you can do things like this:<BR><BR>&#060;%<BR>tomorrow = Date() + 1<BR>yesterday = Date() - 1<BR><BR>For theDay = Date() To Date()+7<BR> Response.Write theDay & "&#060;br/&#062;"<BR>Next<BR>%&#062;<BR><BR>The FOR statement is especially marvelous. It knows to add 1 to "theDay" each time through the loop *without* converting "theDay" to a numeric value!<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
6,476

## In some cases it makes sense

But for the most part, one should not take on the examples we been looking at...<BR>Ever try converting to .net would be a nightmare...<BR>let alone just trying to figure out code when errors arrise.<BR><BR>Usually where it bites me is on case examples where i did this.<BR><BR>intMyVal = "4"<BR><BR>Select Case(intMyVal)<BR>Case 1<BR><BR>Case 2<BR><BR>Case 3<BR><BR>Case 4<BR><BR>End Select<BR><BR>Long time ago this caught me many times scratching my head for hours why i could not get a match...<BR>hehehehe<BR><BR>Live & learn.<BR><BR>Russell M

10. Senior Member
Join Date
Dec 1969
Posts
6,476

## Darn, would not have posted

if i looked at the time.<BR><BR>Sorry<BR>Russ

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•