0% found this document useful (0 votes)
25 views

Answer Assignment 02 PDF

The document provides instructions for creating a Visual Basic .NET application to calculate sales tax. It involves designing a form with labels and text boxes to accept a purchase price and display the calculated sales tax and final price. A constant is used to store the sales tax rate, and buttons are added to trigger a calculation that determines the sales tax amount and final price based on the entered purchase price. The calculations are performed by variables and the results displayed in the appropriate text boxes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Answer Assignment 02 PDF

The document provides instructions for creating a Visual Basic .NET application to calculate sales tax. It involves designing a form with labels and text boxes to accept a purchase price and display the calculated sales tax and final price. A constant is used to store the sales tax rate, and buttons are added to trigger a calculation that determines the sales tax amount and final price based on the entered purchase price. The calculations are performed by variables and the results displayed in the appropriate text boxes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Design and program following applications using visual basic .

NET

1. Sales Tax Calculation

2.
Sales Tax Calculation Create a simple application to calculate the sales tax for a
purchase. It will use a constant in order to indicate the sales tax percentage. Perform the
following steps Create Form:

Step 1: Create a new project called Sales Tax Calculation.

Step 2: Set the Name property of the form to frmSalesTax.

Step 3: Set the Text property to Sales Tax Calculation.

Step 4: Right-click on Form1.vb in the Solution Explorer and rename the form to
frmSalesTax.vb.

Add Title Label:

Step 1: Click on the label control in the Control toolbox.

Step 2: Draw a label control on the form.

Step 3: Set the Name property of the label to lblTitle.

Step 4: Change the Text property to Sales Tax Calculation.

Step 5: Change the Font Size property to 14 and the Font Bold to True.

Step 6: Change the TextAlign property to MiddleCenter.


Purchase Price Label:

Step 1: Place a label control on the form.

Step 2: Change the Name property to lblPurchasePrice.

Step 3: Change the Text property to Purchase Price.

Step 4: Change the Font Size property to 14 and the Font Bold property to True. Add
Sales Tax Label :

Step 1: Place a label control on the form.

Step 2: Change the Name property to lblSalesTax.

Step 3: Change the Text property to Sales Tax.

Step 4: Change the Font Size property to 14 and the Font Bold property to True.

Add Final Price Label:

Step 1: Place a label control on the form.

Step 2: Change the Name property to lblFinalPrice.

Step 3: Change the Text property to Final Price.

Step 4: Change the Font Size property to 14 and the Font Bold property to True.

Add Purchase Price Text Box:

Step 1: Place a text box control on the form.

Step 2: Change the Name property to txtPurchasePrice.

Step 3: Erase the value in the Text property.


Add Sales Tax Text Box:

Step 1: Place a text box control on the form.

Step 2: Change the Name property to txtSalesTax.

Step 3: Erase the value in the Text property.

Add Final Price Text Box:

Step 1: Place a text box control on the form.

Step 2: Change the Name property to txtFinalPrice.

Step 3: Erase the value in Text property.


Add Calculation Button:

Step 1: Place a button control on the form.

Step 2: Set the Name property of the control to btnCalculate.

Step 3: Change the Text property to Calculate.

Add Code to the Button:

Step 1: Double-click on the btnCalculate button.


Step 2: Type the declaration to define a constant called decSalesTaxRate as a Decimal
data type and set it equal to 0.06.
Step 3: Declare three variables: decSalesTaxAmount, decFinalPrice, and
decPurchasePrice.
Step 4: Convert the value stored in the txtPurchasePrice text box to a numerical value
and store it in the decPurchasePrice variable.

Step 5: Calculate the decSalesTaxAmount by multiplying the decSalesTaxRate by


decPurchasePrice.

Step 6: Calculate the decFinalPrice by adding the amount stored in the decPurchasePrice
and decSalesTaxAmount.

Step 7: Store the decSalesTaxAmount in the txtSalesTax text box.

Step 8: Store the decFinalPrice in the txtFinalPrice text box.

Add Calculation Button:

Step 1: Place a button control on the form.

Step 2: Set the Name property of the control to btnCalculate.

Step 3: Change the Text property to Calculate.


Add Code to the Button:

Step 1: Double-click on the btnCalculate button.

Step 2: Type the declaration to define a constant called decSalesTaxRate as a Decimal


data type and set it equal to 0.06.

Step 3: Declare three variables: decSalesTaxAmount, decFinalPrice, and


decPurchasePrice.

Step 4: Convert the value stored in the txtPurchasePrice text box to a numerical value
and store it in the decPurchasePrice variable.

Step 5: Calculate the decSalesTaxAmount by multiplying the decSalesTaxRate by


decPurchasePrice.

Step 6: Calculate the decFinalPrice by adding the amount stored in the decPurchasePrice
and decSalesTaxAmount.

Step 7: Store the decSalesTaxAmount in the txtSalesTax text box.

Step 8: Store the decFinalPrice in the txtFinalPrice text box.


3.5 Complex Operators
Visual Basic.NET provides several complex operators.
You will often wish to perform such mathematical operations as adding a number to,
subtracting a number from, or multiplying a number by an existing variable and store the
result back in the same variable. Refer to this table for a list of operators for that
purpose:
Operation Long Way of Writing the Statement Short Way of Writing the Statement

Addition intVar = intVar + 1 intVar += 1


Subtraction intVar = intVar – 1 intVar -= 1
Division intVar = intVar / 1 intVar /= 1
Multiplication intVar = intVar * 1 intVar *= 1
String concatenation strVar = strVar & “New Text” strVar &= “New Text”

Drill 3.11
What is the output if the btnOperators’ Click event is executed?

Answer: The final value of intDrillValue is 10 and it is output in a message box.

Drill 3.12
What is the output if the btnOperators’ Click event is executed?

Answer: The final value of intDrillValue is 10 and it is output in a message box.


Drill 3.13
What is the output if the btnOperators’ Click event is executed?

Answer: “This and that” is output in the message box.

Drill 3.14
What is the output if the btnOperators’ Click event is executed?

Answer: “that” is output in the message box.


3.6 Using the Debugger
As your programs become more complex, you will need more sophisticated ways of
determining the source of errors. You must learn how to use the Debugger. You will use
the previous example and step through its execution. You will set a breakpoint at the
start of the code you wrote. A breakpoint is a signal to the Debugger to stop the
execution of the application and wait for further instructions on how to continue
executing the application.

Start the Debugger


Step 1: A breakpoint is set by clicking to the left of the code you wish to be set as the
breakpoint. In the figure below the breakpoint is set to the beginning of the Click event
code for the btnCalculate button.
Execute the Application

Step 2: Start running the application in the normal manner by clicking on the Start
button or hitting the key. Step 3: Enter a value for the purchase price, 49.95. Do not
enter the dollar sign.

Stepping Into Code


Step 4: Click on the btnCalculate button. Notice that instead of executing the code, the
actual code is displayed. You are now in the Visual Basic.NET Debugger. The yellow
highlighting indicated what line you are about to execute. You can step through the
Click event line by line by clicking on the Debug menu item and then clicking on Step
Into or you can press the key.
Stepping Over Code
Step 5: Unlike in Step 4, to move to the next line of code, use the key instead of. The
key will step over code instead of stepping into it. By stepping over code you will
prevent the accidental entry into additional code that may complicate the tracing of the
application. Press the key once. Notice how the yellow line skips over the declarations
and is over the first line of code to be executed. You cannot trace the declaration of
variables.
3. Instock and out of stock
Example: In Stock?
PROBLEM DESCRIPTION
The application will ask the user to enter the amount of a product a company has on
hand. If the number is greater than 0, then the program outputs that the “Product is in
Stock”. Otherwise, it outputs that the “Product is Sold Out”.

PROBLEM DISCUSSION
It will require creating a form with a txtStockAmount text box to store the amount of a
product a company has in stock, a lblAmount label with the Text property set to
“Amount in Stock”, another label, lblInStock, to hold a message, and a button with the
Text property set to “Calculate”. The code of the program compares the number entered
by the user to 0. The Visual Basic .NET Coach
PROBLEM SOLUTION:
Create Project and Form:
Step 1: From the Start window, click on New Project. The New Project window will
appear.
Step 2: Specify the name of the application as InStock.
Step 3: Specify the location as "C:\VB Net Coach\Chapter 4\Code\ ".
Step 4: Click on the OK button.
Step 5: Rename the form to frmInStock.
Step 6: Rename the file by right-clicking on the file name in the Solution Explorer and
setting the name to frmInStock.vb.
Step 7: Set the Text property of the form to In Stock. The Visual Basic .NET Coach.

Add the In Stock Label:


Step 1: Place a label control across the top of the form.
Step 2: Set the Name property to lblInStock.
Step 3: Clear the Text property.

Add the Amount In Stock Label:


Step 1: Place a label control to the right and about halfway down the form.
Step 2: Set the Name property to lblAmount.
Step 3: Set the Text property to Amount in Stock.
Step 4: Set the Font Bold property to True.

Add the Stock Amount Text Box:


Step 1: Place a text box control below the In Stock label.
Step 2: Set the Name property to txtStockAmount.
Step 3: Clear out the default value from the Text property. The Visual Basic .NET
Coach.
Add the Calculate Button:
Step 1: Place a button control in the left side of the form, below the text box.
Step 2: Set the Name property to btnCalculate.
Step 3: Set the Text property to Calculate.
Step 4: Double-click on the button.
Step 5: Attach the code to output a message as to whether an item is in stock. The
Visual Basic .NET Coach

Here are two possible outputs:

You might also like