Thursday, October 7, 2010

Sales Tax Calculation Program

How to Write Simple Sales Tax Calculation Program
in Visual Basic .Net 2008 by Using Visual Studio 2008

There are two factors that determine the sales tax, first is the retail price of the item, the second is the sales tax percentage. If you have these two information then you can easily calculate sales tax and price after sales tax.

For example here, to calculate the Sales Tax Amount you have to multiply the retail price of the item and sales tax percentage and then divide the result on 100, This way you will get the sales tax amount. by adding this sales tax amount to original retail price you will get the price after sales tax. below is simple program which will help you to calculate sales tax on your computer.
  • Start your visual studio program.
  • Select File -> New Project
  • Select Project Type Visual Basic -> Windows and from Templates Windows Form Application
  • Below write the name of your application "SalesTaxCalculator"
  • Press OK button


Fig 1 : New Project Window


Fig 2: Property Window Button

Now you have created your new project with name "SalesTaxCalculator". Here you can see your form on your left side window. Open your property window if it is not already opened by clicking the button on tool bar.




Fig 3 : Workplace
 
In the property window you will see the text property of form just type there "Sales Tax Calculator", it would become the caption of your program.

Fig 4 Form Layout
Select a label control from the toolbox window and drop it on the form, in the property window select the property text and write "Sales Tax Calculator" in it. then select the font property, set bold style and 14 points font size. now place the label on the form as shown in the fig 4.

Similarly drop four more label controls form the toolbox and change their text property for "Retail Price", "Sales Tax Percentage", "Sales Tax Amount" and  "Price after Sales Tax", then place them according to the fig 4

Now drop two text boxes from the tool box and this time change their name property as "txtRetailPrice" and "txtSalesTax" and place them according to fig 4

Take two more label controls form toolbox window and place them on the form as shown in the fig 4 and change their text property with "0.0", these labels will be used to show the results, secondly change their name property as "lblSalesTaxAmount" and "lblPriceAfterSalesTax"

Drop one button control from the toolbox window on form and change the text property to "Calculate"

Now your form layout is almost ready according to the fig 4. now lets move to program these controls.

Now double click on the calculate button it will take you to the programming window and for the relevant event there we will write the click event of the button.
 copy and past the below code in the button click event 
Enjoy
lblSalesTaxAmount.Text = Val(txtRetailPrice.Text) * Val(txtSalesTax.Text) / 100
lblPriceAfterSalesTax.Text = Val(txtRetailPrice.Text) + lblSalesTaxAmount.Text
after copying this code just hit the F5 function key and Enjoy the Sales Tax Calculator

No comments:

Post a Comment