Service calculator! (Tax and tip) Here is a simple calculator for calculating the tax and tip of a transaction. I have tried to add input verification. I am wondering if there are more elegant ways of doing some simple tasks that are required for this calculator, such as getting the total. Are my naming conventions correct, function use correct, variable (tax) convention correct (should it be static somewhere else?), and clearing/updating of fields as input is being entered into the form. Thank you!!



''' &lt;summary&gt;
''' Author:    Brandon Finley
''' Date:      10/5/2017
''' Purpose:   Calculate the tax and tip of a sale.
''' Status:    Works as intended. I tried to be as clear and consistant as possible.
''' &lt;/summary&gt;

Public Class MainForum
    Dim tax As Double = 0.08

    ' Validates and updates tax and total boxes in dollar value.
    Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click
        If PriceBox.Text.Trim = "" Then
            ' If the PriceBox is empty, a value that isn't a number, or negative move cursor to PriceBox and give user reason.
            MsgBox("Enter a price.",
            MsgBoxStyle.Information, "Missing Information")
            PriceBox.Focus()
        ElseIf IsNumeric(PriceBox.Text) = False Then
            MsgBox("Must enter a number.",
            MsgBoxStyle.Information, "Verify")
            PriceBox.Focus()
        ElseIf PriceBox.Text &lt; 0 Then
            MsgBox("Please enter a positive value into the Price field.",
            MsgBoxStyle.Information, "Verify")
            PriceBox.Focus()
        Else
            TaxBox.Text = Format(GetTax(), "currency")
            TotalBox.Text = Format(CalcTotal(), "currency")
        End If
    End Sub

    ' Returns the tax based on the tax multiplied by the price.
    Function GetTax() As Double
        Return PriceBox.Text * tax
    End Function

Private Function GetTip(PercentTip As GroupBox) As Double
    For Each ctrl As RadioButton In PercentTip.Controls
        If ctrl.Checked Then Return PriceBox.Text * (Microsoft.VisualBasic.Left(ctrl.Text, 2) / 100)
    Next
End Function

        ' Returns the total sales formatted to look like currency.
Private Function GetTotal(IsTipPercent As Boolean) As String
    ' Radio buttons do not return total until CalcButton has been pressed.
    If IsTipPercent = False Or (IsTipPercent = True And TotalBox.Text &lt;&gt; "") Then
        Return Format(CalcTotal(), "currency")
    End If
End Function

' Returns the total of price + tax + tip.
Private Function CalcTotal() As Double
    Return PriceBox.Text + GetTax() + GetTip()
End Function

' Updates price if tip amount changes (only after calculating total first).
' Updates price if tip amount changes (only after calculating total first).
Private Sub Tip15_CheckedChanged(sender As Object, e As EventArgs) Handles Tip15.CheckedChanged, Tip20.CheckedChanged, Tip25.CheckedChanged
    TotalBox.Text = GetTotal(True)
End Sub

    ' Clears the tax and tip fields if original price has been changed. bump
    Private Sub PriceBox_TextChanged(sender As Object, e As EventArgs) Handles PriceBox.TextChanged
        If TotalBox.Text &lt;&gt; "" And PriceBox.Text.Trim &lt;&gt; "" Then
            TaxBox.Text = ""
            TotalBox.Text = ""
        End If
    End Sub

    ' Exits application.
    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub

End Class
My only concern would be the hard coding of 15, 20, and 25, and the redundant code used to handle these 3 values:

Private Function GetTip() As Double
    If (Tip15.Checked) Then
        Return PriceBox.Text * 0.15
    ElseIf (Tip20.Checked) Then
        Return PriceBox.Text * 0.2
    ElseIf (Tip25.Checked) Then
        Return PriceBox.Text * 0.25
    End If
End Function


[...]

Private Sub Tip15_CheckedChanged(sender As Object, e As EventArgs) Handles Tip15.CheckedChanged
    If TotalBox.Text &lt;&gt; "" Then
        TotalBox.Text = Format(CalcTotal(), "currency")
    End If
End Sub
Private Sub Tip20_CheckedChanged(sender As Object, e As EventArgs) Handles Tip20.CheckedChanged
    If TotalBox.Text &lt;&gt; "" Then
        TotalBox.Text = Format(CalcTotal(), "currency")
    End If
End Sub
Private Sub Tip25_CheckedChanged(sender As Object, e As EventArgs) Handles Tip25.CheckedChanged
    If TotalBox.Text &lt;&gt; "" Then
        TotalBox.Text = Format(CalcTotal(), "currency")
    End If
End Sub


You might want to add more values later (18% seems to be a new popular tip value for some reason) or edit the existing values, so hardcoding isn't a great idea, design/style wise.