Calculating the Tax Amount

Introduction

When a tax rate is applied to an item that is being sold, there is an amount paid as extra besides the marked value of an item. To calculate the tax amount, you use the tax rate and apply it on the price of the item.

  1. Start Microsoft Visual Basic and create a Standard EXE application
  2. Save the application in a new folder named Tax Amount
  3. Save the form as frmMain and save the project as TaxCalculation
  4. Design the form as follows
     
    Control Name Caption/Text Additional Properties
    Form frmMain Tax Amount Calculation Border Style: 3 - FixedDialog
    Label   Marked Price:
    TextBox txtMarkedPrice 0.00 Alignment: 1 - Right Justify
    Label Tax Rate:
    TextBox txtTaxRate 5.75 Alignment: 1 - Right Justify
    Label %
    Button cmdCalculate C&alculate
    Label Tax Amount:
    TextBox txtTaxAmount 0.00 Alignment: 1 - Right Justify
    Label Net Price:
    Text Box txtNetPrice 0.00 Alignment: 1 - Right Justify
    Button cmdClose &Close
  5. Double-click the Close button and return to the form
  6. Double-click the Calculate button
  7. Implement the events as follows:
     
    Option Explicit
    
    Private Sub cmdCalculate_Click()
        Dim MarkedPrice As Currency
        Dim TaxRate As Double
        Dim TaxAmount As Currency
        Dim NetPrice As Currency
        
        MarkedPrice = CCur(txtMarkedPrice.Text)
        TaxRate = txtTaxRate.Text / 100
        TaxAmount = MarkedPrice * TaxRate
        NetPrice = MarkedPrice + TaxAmount
        
        txtMarkedPrice.Text = FormatCurrency(MarkedPrice)
        txtTaxAmount.Text = FormatCurrency(TaxAmount)
        txtNetPrice.Text = FormatCurrency(NetPrice)
    End Sub
    
    Private Sub cmdClose_Click()
        End
    End Sub
  8. Test the application
     
 
 

Copyright 2004 FunctionX, Inc.