PROGRAMMING WITH MICROSOFT VIS PKG
PROGRAMMING WITH MICROSOFT VIS PKG
7th Edition
ISBN: 9781337088152
Author: ZAK
Publisher: CENGAGE L
Question
Book Icon
Chapter 4.LC, Problem 2E
Program Plan Intro

Bakery application

Program plan:

  • Create new Windows Forms Application.
  • Design the form by placing the labels, textbox, and button and then change their name and properties.
  • Inside the “Calculate” button,
    • Declare required variables.
    • Assign the name to the variables.
    • Calculate the items sold.
    • Calculate the sub total
    • Calculate the sales tax.
    • Display total amounts.
    • Display tax and sales clerk’s name.
  • Inside the “Exit” button,
    • Close the form.
  • Inside the “btnPrint_Click”
    • Print the sales receipt.
  • Inside the “txtDate_Enter”
    • Select all the values.
  • Inside the “txtDate_keyPress”,
    • Check the condition.
  • Inside the “txtDonuts_Enter”,
    • Select all the text.
  • Inside the “CancelKeys”,
    • Check the condition.
  • Inside the “txtMuffins_Enter”,
    • Select all the text.

Expert Solution & Answer
Check Mark
Program Description Answer

This program is to modify the bakery application.

Explanation of Solution

Program:

'Definition of class frmMain

Public Class frmMain

    'Definition of button calculate

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click

        ' Calculate number of items sold and total sales

        Const PromtMsg As String = "Salesclerk's name:"

        Const title As String = "Name Entry"

        Const ItemPrice As Decimal = 0.5D

        Const tax As Decimal = 0.02D

        Dim donuts As Integer

        Dim muffins As Integer

        Dim totalItems As Integer

        Dim subTotal As Decimal

        Dim salesTax As Decimal

        Dim totalSales As Decimal

        Static clerk As String

        'Assign the name to variable

        clerk = InputBox(PromtMsg, title, clerk)

        ' Calualte the items sold

        Integer.TryParse(txtDonuts.Text, donuts)

        Integer.TryParse(txtMuffins.Text, muffins)

        totalItems = donuts + muffins

        ' calculate the subtotal

        subTotal = totalItems * ItemPrice

        ' calculate the sales tax

        salesTax = subTotal * tax

        ' calculate the total sales

        totalSales = subTotal + salesTax

        ' display total amounts

        lblTotalItems.Text = Convert.ToString(totalItems)

        lblTotalSales.Text = totalSales.ToString("C2")

        ' display tax and salesclerk's name

        lblMsg.Text = "The sales tax was " &

            salesTax.ToString("C2") & "." &

            ControlChars.NewLine & clerk

    End Sub

    'Definition of button clear

    Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click

        'Assign text box to empty

        txtDonuts.Text = String.Empty

        txtMuffins.Text = String.Empty

        lblTotalItems.Text = String.Empty

        lblTotalSales.Text = String.Empty

        lblMsg.Text = String.Empty

        ' send the focus to the Doughnuts box

        txtDonuts.Focus()

    End Sub

    'Definition of button exit

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

        'Close the form

        Me.Close()

    End Sub

    'Definition of button print

    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click

        'print the sales receipt

        btnCalc.Visible = False

        btnClear.Visible = False

        btnExit.Visible = False

        btnPrint.Visible = False

        PrintForm1.Print()

        btnCalc.Visible = True

        btnClear.Visible = True

        btnExit.Visible = True

        btnPrint.Visible = True

    End Sub

    'Definition of ClearLabels

    Private Sub ClearLabels(sender As Object, e As EventArgs) _

        Handles txtDonuts.TextChanged, txtMuffins.TextChanged

        ' Clear the total items, total sales, and message

        lblTotalItems.Text = String.Empty

        lblTotalSales.Text = String.Empty

        lblMsg.Text = String.Empty

    End Sub

    'Definition of txtDate_Enter

    Private Sub txtDate_Enter(sender As Object, e As EventArgs) Handles txtDate.Enter

        'Select all the values

        txtDate.SelectAll()

    End Sub

    'Defintion of txtDate_keyPress

    Private Sub txtDate_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtDate.KeyPress

        'Check the conditon

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso

            e.KeyChar <> "/" AndAlso e.KeyChar <> "-" AndAlso

            e.KeyChar <> ControlChars.Back Then

            e.Handled = True

        End If

    End Sub

    'Definition of txtDonuts_Enter

    Private Sub txtDonuts_Enter(sender As Object, e As EventArgs) Handles txtDonuts.Enter

        'Select all the text

        txtDonuts.SelectAll()

    End Sub

    'Defintion of CancelKeys

    Private Sub CancelKeys(sender As Object, e As KeyPressEventArgs) Handles txtDonuts.KeyPress, txtMuffins.KeyPress

        'Check the condition

        If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then

            e.Handled = True

        End If

    End Sub

    'Definition of txtMuffins_Enter

    Private Sub txtMuffins_Enter(sender As Object, e As EventArgs) Handles txtMuffins.Enter

        'Select all the text

        txtMuffins.SelectAll()

    End Sub

End Class

Sample Output

Run the program, enter the date, number of Doughnuts and Muffins and then click on the “Calculate” button.

Screenshot of form

PROGRAMMING WITH MICROSOFT VIS PKG, Chapter 4.LC, Problem 2E

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Which menu item provides access to the interface's TabIndex boxes?
Extra 6-1     Develop the Temperature Converter In this exercise, you’ll use radio buttons to determine whether the conversion is from Fahrenheit to Celsius or vice versa. You’ll also modify the DOM so the labels change when a radio button is clicked, and the page displays an error message when the user enters invalid data. 1. Open the application in this folder: exercises_extrach06convert_temps 2. Note that the JavaScript file has some starting JavaScript code, including the $() function, three helper functions, three event handler functions, and a DOMContentLoaded event handler that attaches the three event handlers. 3. Review how the toCelsius() and toFarhenheit() event handler functions call the toggleDisplay() helper function and pass it strings to display. Also note that the toggleDisplay() helper function and the convertTemp() event handler function are incomplete. 4. Code the toggleDisplay() function so it changes the text in the labels for the text boxes to the values in the…
Open the application in the folder under the coursework. Open the HTML file and notice that an Invoice Date field has been added. Then, open the HTML file and notice that it includes a getFormattedDate() function that formats the Date object that’s passed to it in MM/DD/YYYY format and then returns the date string. Start the application, enter a subtotal, and click the Calculate button. Note that nothing is displayed in the Invoice Date field. In the click() event handler for the Calculate button, add code that gets the current date and formats it using the getFormattedDate() function. Then, add code that provides a default value of the formatted current date for the invoice date. Note that if an invoice date is entered, that date isn’t validated. Add code that sets the value of the Invoice Date field. If you’ve done this right, the application should display the current date when you click the Calculate button without entering anything in the Invoice Date field.   <!DOCTYPE…
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT