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!

Simple calculations I think 1

Status
Not open for further replies.

Ragol1

Programmer
Oct 25, 2001
315
US
Ok i have a form which I want to add calculations to when it posts.
Here is what I Want it is an invoice i have the form created and its already posts but without the calculations.

field1 X 65
plus
Field2 X 45

Plus field3 (These fields may be empty)
plus field4
Plus field5
plus field6
Plus field7
plus field8

Minus Field9 (Could be empty)

= field10 (I want to display this field as sub total)

Then X field10 by Field11% (this is a % field11)

To give a total in Field12 (I want to display this field as my total)

I hope someoene can help

Thanks

Nick
 
Assuming all fields are strings with numbers:
Code:
Dim total, field10, field12

total = (cDbl(field1) * 65) + (cDbl(field2) * 45)

If field3 <> &quot;&quot; Then total = total + cDbl(field3)
If field4 <> &quot;&quot; Then total = total + cDbl(field4)
If field5 <> &quot;&quot; Then total = total + cDbl(field5)
If field6 <> &quot;&quot; Then total = total + cDbl(field6)
If field7 <> &quot;&quot; Then total = total + cDbl(field7)
If field8 <> &quot;&quot; Then total = total + cDbl(field8)
If field9 <> &quot;&quot; Then total = total - cDbl(field9)

field10 = total

'In case your tax is listed as .06 rather than 1.06
If cDbl(field11) < 1 AND cDbl(field11) > 0 Then field11 = cDbl(field11) + 1
total = total * cDbl(field11)

field12 = total

Response.Write &quot;SubTotal: &quot; & field10
Response.Write &quot;Total: &quot; & field12

This assumes all fields are strings, if they are all definately numbers than you won't need the cDbl's and instead of checking for <> &quot;&quot; then check for > 0

-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Its nearly there the tax should be sub total (times by %) of the tax field.

Can I do this
 
Sorry it should be Sub total + whatever the tax field is %
 
Code:
Dim total, field10, field12

total = (cDbl(field1) * 65) + (cDbl(field2) * 45)

If field3 <> &quot;&quot; Then total = total + cDbl(field3)
If field4 <> &quot;&quot; Then total = total + cDbl(field4)
If field5 <> &quot;&quot; Then total = total + cDbl(field5)
If field6 <> &quot;&quot; Then total = total + cDbl(field6)
If field7 <> &quot;&quot; Then total = total + cDbl(field7)
If field8 <> &quot;&quot; Then total = total + cDbl(field8)
If field9 <> &quot;&quot; Then total = total - cDbl(field9)

field10 = total             'subtotal before tax

Dim tax
tax = total * cDbl(field11) 'tax on subtotal
total = total + tax         'final total with tax

field12 = total

Response.Write &quot;SubTotal: &quot; & field10
Response.Write &quot;Tax: &quot; & (field10 * field11)
Response.Write &quot;Total: &quot; & field12
------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
oops, last three lines should have been
Code:
Response.Write &quot;SubTotal: &quot; & field10
Response.Write &quot;Tax: &quot; & tax
Response.Write &quot;Total: &quot; & field12
------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Ok i got it but the total now displays figures like 507.0251

Can I just make it disply two digits like this would be .02 figure

589.2355 would be 589.23

Thanks
 
total = FormatPercent(total) will give it 2 decimal places, thanks to JuanitaC and Onpnt a few posts down from bringing that to the top of my memory :)
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
I want to round it up 507.8956 would be 507.90

Thanks
 
Try the round function:
total = Round(total,2)
Can't remember if this ASP3 or ASP.Net or both
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Thanks you have been a great help, I added the round function but it just rounds it to 2 digits not up or down so I think after the calculations I will just add .01 to the total

Thanks

Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top