2021年3月6日星期六

Understandind data validation in VBA

I am working on an assignment for school where I have to validate a data entry. My first issue is that running the function does not produce an error message when I run the code and use any other letter as customer type.

My second issue is that the 40% discount for the Else clause that is commented out is applying even though it is commented out.

Private Sub GetDiscountPercent(customerType As String, subtotal As Decimal,                                 ByRef discountPercent As Decimal)      If customerType = "R" Then          If subtotal < 100 Then              discountPercent = 0          ElseIf subtotal >= 100 AndAlso subtotal < 250 Then              discountPercent = 0.1D          ElseIf subtotal >= 250 Then              discountPercent = 0.25D          End If      ElseIf customerType = "C" Then          If subtotal < 250 Then              discountPercent = 0.2D          Else              discountPercent = 0.3D          End If          'Else          'discountPercent = 0.4D      End If  End Sub    Private Sub btnExit_Click(sender As Object,          e As EventArgs) Handles btnExit.Click      Me.Close()  End Sub    Private Sub ClearResultBoxes(sender As Object,          e As EventArgs) _          Handles txtCustomerType.TextChanged, txtSubtotal.TextChanged      txtDiscountPercent.Text = ""      txtDiscountAmount.Text = ""      txtTotal.Text = ""  End Sub    Function IsValidCustomerType() _  As Boolean      If IsValidCustomerType = "R" Then          MessageBox.Show("Customer Type has to be R or C or T", "Entry Error")          txtCustomerType.Select()          Return False      Else          Return True      End If      If Not IsValidCustomerType = "C" Then          MessageBox.Show("Customer Type has to be R or C or T", "Entry Error")          txtCustomerType.Select()          Return False      Else          Return True      End If  End Function  

End Class

https://stackoverflow.com/questions/66512155/understandind-data-validation-in-vba March 07, 2021 at 08:43AM

没有评论:

发表评论