Forums
This topic is locked
ASP EXPERTS...PROVE YOUR WORTH
Posted 10 Jun 2003 18:41:24
1
has voted
10 Jun 2003 18:41:24 Frank Munoz posted:
I have a very hard issue and can't seem to find answers anywhere.What I want to do is know how to calculate (sum, multiply, ect.) between "dynamic text fields" that are part of a calculation, as opposed to values from a recordset.
Example: {Hours.Quantity}*{Rate.Amount}
Result: {TotalAmount}
I know you can calculate like the following:
SELECT Sum(Quantity+Amount)
FROM TimeSheet
Where CustID = varCustID
But I don't want to calculate using query recordsets, instead I wan't to calculate between "Dynamic Text Fields" just like among text fields.
Does anyone know how this can easily be done?
Replies
Replied 11 Jun 2003 09:15:28
11 Jun 2003 09:15:28 Vince Baker replied:
use this example page to do what you want.
<%@LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="VBScript">
sub DoCalculation()
if document.CalculationForm.Text01.value <> 0 and document.CalculationForm.Text02.value <> 0 then
document.CalculationForm.Result01.value = document.CalculationForm.Text01.value * document.CalculationForm.Text02.value
end if
end sub
</script>
</head>
<body>
<form action="" method="post" name="CalculationForm" id="CalculationForm">
<p>
<input name="Text01" type="text" id="Text01" onBlur="DoCalculation()" value="0">
</p>
<p>
<input name="Text02" type="text" id="Text02" onBlur="DoCalculation()" value="0">
</p>
<p>
<input name="Result01" type="text" id="Result01">
</p>
</form>
</body>
</html>
Regards
Vince
Visit my home: www.chez-vince.com
VBScript | ASP | HTML | SQL | Oracle | Hosting
<%@LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="VBScript">
sub DoCalculation()
if document.CalculationForm.Text01.value <> 0 and document.CalculationForm.Text02.value <> 0 then
document.CalculationForm.Result01.value = document.CalculationForm.Text01.value * document.CalculationForm.Text02.value
end if
end sub
</script>
</head>
<body>
<form action="" method="post" name="CalculationForm" id="CalculationForm">
<p>
<input name="Text01" type="text" id="Text01" onBlur="DoCalculation()" value="0">
</p>
<p>
<input name="Text02" type="text" id="Text02" onBlur="DoCalculation()" value="0">
</p>
<p>
<input name="Result01" type="text" id="Result01">
</p>
</form>
</body>
</html>
Regards
Vince
Visit my home: www.chez-vince.com
VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 11 Jun 2003 14:51:43
11 Jun 2003 14:51:43 Frank Munoz replied:
Thanks Vince, the example works great, but is there a way to calculate "Dynamic Text Fields" that each are already making a calculation themselves, instead of input text fields? Is it possible or am I asking for too much?
Replied 11 Jun 2003 15:31:47
11 Jun 2003 15:31:47 Owen Eastwick replied:
Yes you can make calculations from recordset values, just as with variables, for example:
varHours = rsName.Fields.Item("Hours".Value
varRate = rsName.Fields.Item("Rate".Value
varTotal = varHours * varRate
You can then display it how you want on the page, for example:
Number of hours: <%= varHours %><br>
Hourly Rate: <%= varRate %><br>
Total Cost: <%= varTotal %>
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
varHours = rsName.Fields.Item("Hours".Value
varRate = rsName.Fields.Item("Rate".Value
varTotal = varHours * varRate
You can then display it how you want on the page, for example:
Number of hours: <%= varHours %><br>
Hourly Rate: <%= varRate %><br>
Total Cost: <%= varTotal %>
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
Replied 11 Jun 2003 16:40:09
11 Jun 2003 16:40:09 Frank Munoz replied:
Hey Owen...thanks...it seems I'm getting closer with your example, but how can I calculate the last {varTotal} field in your example with another Total field of another calculated expression...to come up with subtotal especially if the subtotal is summing up the Total from a repeat region?
Replied 11 Jun 2003 19:15:02
11 Jun 2003 19:15:02 Owen Eastwick replied:
Something like:
<% varGrandTotal = 0 %>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsName.EOF))
%>
<tr>
<td><%= varTotal %></td>
</tr>
<% varGrandTotal = varGrandTotal + varTotal %>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsName.MoveNext()
Wend
%>
Then display the grand total on the page, something like:
Grand Total: <%= varGrandTotal %>
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/
<% varGrandTotal = 0 %>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsName.EOF))
%>
<tr>
<td><%= varTotal %></td>
</tr>
<% varGrandTotal = varGrandTotal + varTotal %>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsName.MoveNext()
Wend
%>
Then display the grand total on the page, something like:
Grand Total: <%= varGrandTotal %>
Regards
Owen.
-------------------------------------------------------------------------------------------
Used programming books and web development software for sale (UK only): www.tdsf.co.uk/tdsfdemo/Shop.htm
Developer services and tutorials: www.drdev.net
Multiple Parameter UD4 / Access 2000 Search Tutorial: www.tdsf.co.uk/tdsfdemo/