Ascentient
IS-IT--Management
- Nov 4, 2002
- 267
For those of you who viewed my Search String thread here is what I have done with it.
This Code gets the job done, but it looks ugly. The synopsis of this debauchery is replacing the pennies position with a 0 or 5 depending on what the pennies position holds. (Missouri Rounding as it was termed in my previous thread.)
More or less when a discount is applied that discounted price is rounded to the nearest nickel. The are some several naming conventions I have not corrected yet. (IF you notice at all.)
Any suggestions on making this look "clean"?
Dim curDiscountedPrice As Currency
Dim curDollarAmount, curChangeAmount As String
Me![Description] = Me![cboMaterial].Column(1)
' Calculating Sale Price based on Price Scale.
If Form_frmQuotedJob.fraPriceScale.Value = 2 Then 'standard retail price
Me!PricePerTon = cboMaterial.Column(2)
Else 'Contractors Pricing
'Determine the Discounted Price and then break them apart for testing below.
curDiscountedPrice = (cboMaterial.Column(2) - (Round((cboMaterial.Column(2) * 0.06), 2)))
curChangeAmount = Format(curDiscountedPrice - Int(curDiscountedPrice), "#.#0")
curDollarAmount = Val(Split(Trim(Str(curDiscountedPrice)), ".", -1)(0))
'TESTING FOR 1 & 2 to Round Down to Zero.
If Right(curChangeAmount, 1) >= 1 And Right(curChangeAmount, 1) <= 2 Then
curChangeAmount = Format(Val(Mid(Trim(Str(curChangeAmount)), 2, 1) & "0") / 100, "#.#0")
End If
'TESTING FOR 3 & 4 to Round Up to 5 and 6 & 7 Round Down to 5
If Right(curChangeAmount, 1) >= 3 And Right(curChangeAmount, 1) <= 4 Or Right(curChangeAmount, 1) >= 6 And Right(curChangeAmount, 1) <= 7 Then
l1 = Val(Mid(Trim(Str(curChangeAmount)), 2, 1))
curChangeAmount = Val(Mid(Trim(Str(curChangeAmount)), 2, 1) & "5") / 100
End If
'TESTING FOR 8 & 9 to Round UP to Zero (.38 rounds to .40)
If Right(curChangeAmount, 1) >= 8 And Right(curChangeAmount, 1) <= 9 Then
If Mid(Trim(Str(curChangeAmount)), 2, 1) = 0 Then
curChangeAmount = 0.1
ElseIf Mid(Trim(Str(curChangeAmount)), 2, 1) < 9 Then
'Change condition for < 10 to check for Zero. Then perform data otherwise do below.
curChangeAmount = Val(Mid(curChangeAmount, 2, 1) + 1 & "0") / 100 ' Checks for anything less than .95
Else
' Change Amount is $1.00 since change was originally .98 or .99
curChangeAmount = 1 ' Pennies
End If
End If
'Form_frmQuotedJob.txtDiscPrice = curDiscountedPrice
'Form_frmQuotedJob.txtRegPrice = cboMaterial.Column(2)
'Form_frmQuotedJob.txtChange = curChangeAmount
'Form_frmQuotedJob.txtDollar = Val(Left(Trim(Str(curDiscountedPrice)), Len(Trim(curDiscountedPrice)) - 3))
Me!PricePerTon = (curDollarAmount + (curChangeAmount))
End If
This Code gets the job done, but it looks ugly. The synopsis of this debauchery is replacing the pennies position with a 0 or 5 depending on what the pennies position holds. (Missouri Rounding as it was termed in my previous thread.)
More or less when a discount is applied that discounted price is rounded to the nearest nickel. The are some several naming conventions I have not corrected yet. (IF you notice at all.)
Any suggestions on making this look "clean"?
Dim curDiscountedPrice As Currency
Dim curDollarAmount, curChangeAmount As String
Me![Description] = Me![cboMaterial].Column(1)
' Calculating Sale Price based on Price Scale.
If Form_frmQuotedJob.fraPriceScale.Value = 2 Then 'standard retail price
Me!PricePerTon = cboMaterial.Column(2)
Else 'Contractors Pricing
'Determine the Discounted Price and then break them apart for testing below.
curDiscountedPrice = (cboMaterial.Column(2) - (Round((cboMaterial.Column(2) * 0.06), 2)))
curChangeAmount = Format(curDiscountedPrice - Int(curDiscountedPrice), "#.#0")
curDollarAmount = Val(Split(Trim(Str(curDiscountedPrice)), ".", -1)(0))
'TESTING FOR 1 & 2 to Round Down to Zero.
If Right(curChangeAmount, 1) >= 1 And Right(curChangeAmount, 1) <= 2 Then
curChangeAmount = Format(Val(Mid(Trim(Str(curChangeAmount)), 2, 1) & "0") / 100, "#.#0")
End If
'TESTING FOR 3 & 4 to Round Up to 5 and 6 & 7 Round Down to 5
If Right(curChangeAmount, 1) >= 3 And Right(curChangeAmount, 1) <= 4 Or Right(curChangeAmount, 1) >= 6 And Right(curChangeAmount, 1) <= 7 Then
l1 = Val(Mid(Trim(Str(curChangeAmount)), 2, 1))
curChangeAmount = Val(Mid(Trim(Str(curChangeAmount)), 2, 1) & "5") / 100
End If
'TESTING FOR 8 & 9 to Round UP to Zero (.38 rounds to .40)
If Right(curChangeAmount, 1) >= 8 And Right(curChangeAmount, 1) <= 9 Then
If Mid(Trim(Str(curChangeAmount)), 2, 1) = 0 Then
curChangeAmount = 0.1
ElseIf Mid(Trim(Str(curChangeAmount)), 2, 1) < 9 Then
'Change condition for < 10 to check for Zero. Then perform data otherwise do below.
curChangeAmount = Val(Mid(curChangeAmount, 2, 1) + 1 & "0") / 100 ' Checks for anything less than .95
Else
' Change Amount is $1.00 since change was originally .98 or .99
curChangeAmount = 1 ' Pennies
End If
End If
'Form_frmQuotedJob.txtDiscPrice = curDiscountedPrice
'Form_frmQuotedJob.txtRegPrice = cboMaterial.Column(2)
'Form_frmQuotedJob.txtChange = curChangeAmount
'Form_frmQuotedJob.txtDollar = Val(Left(Trim(Str(curDiscountedPrice)), Len(Trim(curDiscountedPrice)) - 3))
Me!PricePerTon = (curDollarAmount + (curChangeAmount))
End If