Public Class frmCost

  Dim subTotal As Double
  Const SALES_TAX = 0.05

  Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
    subTotal += CostOfItem()
    txtPrice.Clear()
    txtQuantity.Clear()
    txtPrice.Focus()
  End Sub

  Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    Dim totalCost As Double = subTotal + (SALES_TAX * subTotal)
    txtTotal.Text = FormatCurrency(totalCost)
  End Sub

  Function CostOfItem() As Double
    Dim price As Double = CDbl(txtPrice.Text)
    Dim quantity As Integer = CInt(txtQuantity.Text)
    Dim cost = price * quantity
    Return cost
  End Function

End Class
