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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to show calculations

Status
Not open for further replies.

rchen

IS-IT--Management
Mar 7, 2003
16
0
0
SG
I am trying to show a calculation based on the data that the user puts in. We showed these calculations in a list box in VBA. Does anyone have any suggestions to show these calculations or receipt? We thought about using text area and building a string of the calculation details. I am not too familiar with ASP, so any help would be appreciated.
 
Can you post some code so that I can amend as needed - it is not worth while creating something which you then have to butcher to fit your needs.

Simon
 
Put your calculations into a function on pageb.asp, with the calculation form on pagea.asp, when they submit, split into an array with your function on pageb.asp, have it calculate it, and return it to the browser... I would go more in depth if I knew what you were trying to calculate
 
That's what I was thinking of doing Stim. Here is my code for VBA. As you can see the code was built for VBA. This code calculates items in a form, builds a string, and then replaces the list box with the string as it's row source. I think I can put this in an asp file and then refer this when a submit button is clicked. But I really do not know how to show it. I wanted to show all the details of the calculation, but if all else fails, I can just show the total. If you can help, it would be great. Thanks.

Public Sub CalculateTotal()

Dim dblBaseRate As Currency
Dim dblAgeIncrease As Currency
Dim dblDriverFee As Currency
Dim dblInsurance As Currency
Dim dblAmtPerDay As Currency
Dim intNumDays As Integer
Dim dblDiscounts As Currency
Dim dblCoupon As Currency
Dim strList As String
Dim dblTaxAmt As Currency
Dim bolInternetDiscount As Boolean
Dim dblCouponDiscount As Currency
Dim dblTotal As Currency
Dim dblTransfer As Double
Dim strNewRow As String
Dim strLineBreak As String
Dim strBlankLine As String
Dim strAgeType As String
Dim dblSubtotalOne As Double
Dim dblSubtotalTwo As Double

'If IsNull(Me.lstReservations) Then Exit Sub

strLineBreak = "' ---------';"
strBlankLine = ";"

' store a show base rate
dblBaseRate = Me.txtBaseRate
strNewRow = "'Base Rate:"
strList = Combine(strNewRow, dblBaseRate, True) & "';"

' store and show age increase
dblAgeIncrease = dblBaseRate * AgeIncrease(g_lngCustomerID, strAgeType)
strNewRow = "'Age Increase" & strAgeType & ":"
strList = strList & Combine(strNewRow, dblAgeIncrease, True, "+") & "';"

' store and show extra driver fees
dblDriverFee = Me.cboDrivers * f_ExtraDriverFee
strNewRow = "'Extra Driver Fee:"
strList = strList & Combine(strNewRow, dblDriverFee, True, "+") & "';"

' store and show corporate discount
If Me.chkCorporate = True Then
dblDiscounts = dblDiscounts + g_dblCorporateDiscount * dblBaseRate
strNewRow = "'Corporate Discount (15%):"
strList = strList & Combine(strNewRow, g_dblCorporateDiscount * dblBaseRate, True, "-") & "';"
End If

' store and show the amount for insrurance
If Me.chkInsurance = True Then
dblInsurance = g_dblInsuranceFee
strNewRow = "'Insurance Fee:"
strList = strList & Combine(strNewRow, dblInsurance, True, "+") & "';"
End If

' store and show internet discount
If g_strEmpLogin = "Internet" Then
dblDiscounts = dblDiscounts + g_dblInternetDiscount * dblBaseRate
strNewRow = "'Internet Discount (5%):"
strList = strList & Combine(strNewRow, g_dblInternetDiscount * dblBaseRate, True, "-") & "';"
End If

strList = strList & strLineBreak

' store and show the amount per day subtotal
dblAmtPerDay = dblBaseRate + dblAgeIncrease + dblDriverFee + dblInsurance - dblDiscounts
strNewRow = "'Amount per Day:"
strList = strList & Combine(strNewRow, dblAmtPerDay, True) & "';"


' store and show the number of days
' add one to account for "partial" day
intNumDays = Me.txtEndDate - Me.txtStartDate + 1
strNewRow = "'Number of Days:"
strList = strList & Combine(strNewRow, intNumDays, False, "x") & "';"
strList = strList & strLineBreak

' store and show current subtotal
dblSubtotalOne = intNumDays * dblAmtPerDay
strNewRow = "'Subtotal:"
strList = strList & Combine(strNewRow, dblSubtotalOne, True) & "';"

strList = strList & strBlankLine



' store and show coupon discount
If Me.cboCoupon <> 0 Then
dblCouponDiscount = DLookup(&quot;couponrate&quot;, &quot;tblCouponCode&quot;, &quot;couponcode = &quot; & Me.cboCoupon)
strNewRow = &quot;'Coupon:&quot;
strList = strList & Combine(strNewRow, dblCouponDiscount, True, &quot;-&quot;) & &quot;';&quot;
End If

dblDiscounts = dblDiscounts + dblCouponDiscount

' store and show transfer fee

If CInt(Me.cboStartBranch) <> CInt(Me.cboendbranch) Then
dblTransfer = g_dblTransferFee
dblDiscounts = dblDiscounts - dblTransfer
strNewRow = &quot;'Transfer Fee:&quot;
strList = strList & Combine(strNewRow, dblTransfer, True, &quot;+&quot;) & &quot;';&quot;

End If

strList = strList & strLineBreak

' store and show subtotal two, but only if there is a transfer fee or coupon used

dblSubtotalTwo = dblSubtotalOne - dblDiscounts
If dblCouponDiscount <> 0 Or dblTransfer <> 0 Then
strNewRow = &quot;'Subtotal:&quot;
strList = strList & Combine(strNewRow, dblSubtotalTwo, True) & &quot;';&quot;
strList = strList & strBlankLine
End If

' store and show tax amount
dblTaxAmt = Round(f_TaxRate * dblSubtotalTwo, 2)
strNewRow = &quot;'Tax (&quot; & f_TaxRate & &quot;):&quot;
strList = strList & Combine(strNewRow, dblTaxAmt, True, &quot;+&quot;) & &quot;';&quot;

strList = strList & strLineBreak

' store and show final amount
dblTotal = dblSubtotalTwo + dblTaxAmt
strNewRow = &quot;'Final Total:&quot;
strList = strList & Combine(strNewRow, dblTotal, True) & &quot;';&quot;

Me.lstCalculation.RowSource = strList
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top