Programming with Microsoft Visual Basic 2015 (MindTap Course List)
Programming with Microsoft Visual Basic 2015 (MindTap Course List)
7th Edition
ISBN: 9781285860268
Author: Diane Zak
Publisher: Cengage Learning
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 Visual Basic 2015 (MindTap Course List), 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
Extra 7-2 Add a stopwatch to the Clock application In this exercise, you’ll add a stopwatch feature to a digital clock application. The stopwatch will display elapsed minutes, seconds, and milliseconds. 1. Open the application in this folder: exercises_extra\ch07\clock_stopwatch\ 2. In the JavaScript file, note the $(), displayCurrentTime(), padSingleDigit(), and DOMContentLoaded event handler functions from the Clock application. In addition, note the global variables and starting code for the tickStopwatch(), startStopwatch(), stopStopwatch(), and resetStopwatch() functions. 3. In the tickStopwatch() function, add code that adds 10 milliseconds to the elapsedMilliseconds variable and then adjusts the elapsedMinutes and elapsedSeconds variables accordingly. Then, add code that displays the result in the appropriate span tags in the page. 4. In the startStopwatch() function, add code that starts the stopwatch. Be sure to cancel the default action of the link too. 5. In the…
Fix the following line of code to change the visibility of the btnExitProgram Button object so that you can view it when the program runs. btnExitProgram.Visibilty = Yes
MFC  In the second part of your project, you need to develop a mathematical worksheet graphical interface for elementary school students. The worksheet consists of 10 questions of operations between two random numbers. The operations are defined randomly from the set {+, -, *, /}. The GUI uses a text field to enter the maximum value of random numbers. A button with the caption "Check Answers" should be added to the GUI, and when clicked, a correct icon () should appear in front of the correct answer and an incorrect icon
Knowledge Booster
Background pattern image
Similar questions
SEE MORE 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
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT