Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the problem that I am working on: http://www.chegg.com/homework-help/sal

ID: 3665081 • Letter: T

Question

This is the problem that I am working on: http://www.chegg.com/homework-help/salesperson-earns-weekly-base-salary-plus-commission-sales-q-chapter-5-problem-3pe-solution-9780077398576-exc

I keep getting the following 4 errors:

Below is my code - please help me make this project work with Option Strict On (the errors occur with the code for the Pay Menu Option)

Public Class Form1
    'Constants
    Const QUOTA As Double = 1000D
    Const COMMISSION_RATE As Decimal = 0.15D
    Const BASE_RATE As Decimal = 250D
    'Double Variables
    Private Sales As Double = 0
    Private Commission As Double = 0
    Private TotalSales As Double = 0
    Private TotalComm As Double = 0
    Private TotalPay As Double = 0
    'String Variable
    Private MessageString As String

    'Function to calculate commission
    Private Function CommissionFunction(ByVal Sales As Double) As Double
        Sales = Double.Parse(WeeklySalesText.Text)
        If Sales >= QUOTA Then
            Commission = Sales * COMMISSION_RATE
        End If
        Return Commission
    End Function

    'Pay Menu Option
    Private Sub PayToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PayToolStripMenuItem.Click
        Commission = 0
        Commission = CommissionFunction(WeeklySalesText.Text)
        CommissionLabel.Text = Commission
        Sales = Double.Parse(WeeklySalesText.Text)
        If Commission > 0 Then
            TotalPayLabel.Text = Commission + Sales
            TotalComm += Commission
        End If

        TotalPayLabel.Text = BASE_RATE
        TotalSales = TotalSales + Sales
        TotalPay = TotalPay + BASE_RATE + Commission
    End Sub

    'Summary Menu Option
    Private Sub SummaryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SummaryToolStripMenuItem.Click
        MessageString = "Total Sales: " &
            TotalSales.ToString("C") &
            Environment.NewLine &
            Environment.NewLine &
            "Total Commission: " &
            TotalComm.ToString("F2")

        MessageBox.Show(MessageString, "Sales Commission Summary",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
    End Sub

    'Exit Menu Option
    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    'Clear Menu Option
    Private Sub ClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClearToolStripMenuItem.Click
        EmpNameText.Clear()
        WeeklySalesText.Clear()
        CommissionLabel.Text = ""
        TotalPayLabel.Text = ""

        With EmpNameText.Focus()
        End With
    End Sub

    'Font Menu Option
    Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
        With FontDialog
            .ShowDialog()
            .Font = TotalPayLabel.Font
            TotalPayLabel.Font = .Font
        End With
    End Sub

    'Color Menu Option
    Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
        With ColorDialog
            .ShowDialog()
            .Color = TotalPayLabel.ForeColor
            TotalPayLabel.ForeColor = .Color
        End With
    End Sub

    'About Menu Option
    Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
        MessageBox.Show("Programmed By Kelly Domerstad",
                        "Sales Commission Project",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
    End Sub
End Class

Explanation / Answer

//Please note I have marked some code which is prone to errors in BOLD and gave corrections in just ablove of every corrupted Line.

Public Class Form1
    'Constants
    Const QUOTA As Double = 1000D
    Const COMMISSION_RATE As Decimal = 0.15D
    Const BASE_RATE As Decimal = 250D
    'Double Variables
    Private Sales As Double = 0
    Private Commission As Double = 0
    Private TotalSales As Double = 0
    Private TotalComm As Double = 0
    Private TotalPay As Double = 0
    'String Variable
    Private MessageString As String

    'Function to calculate commission

//Here you use Double.parse() .

//I would suggest use tryParse(). It works differently from Parse, The problem is that .Parse will throw that exception if it can't FULLY parse the string in the box. Anything can cause failure, including a space, incorrect character, or anything else, so only TryParse is really safe..

// Double.TryParse(WeeklySalesText.Text, Sales)


    Private Function CommissionFunction(ByVal Sales As Double) As Double
        Sales = Double.Parse(WeeklySalesText.Text)
        If Sales >= QUOTA Then
            Commission = Sales * COMMISSION_RATE
        End If
        Return Commission
    End Function

    'Pay Menu Option
    Private Sub PayToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PayToolStripMenuItem.Click
        Commission = 0

//Here CommissionFunction(WeeklySalesText.Text) in this function call you have pass string type argument but in defination of this function you have mentioned argument is of double type. SO when Strict option is on It will not automatically parse string to double. You have to do it explicitly. Use TryParse here also.
        Commission = CommissionFunction(WeeklySalesText.Text)

// Here you are assigning double value to textBox. as strict option is On you need to do "CommissionLabel.Text = Commission.ToString()"
        CommissionLabel.Text = Commission

//Again use Double.tryParse()
        Sales = Double.Parse(WeeklySalesText.Text)
        If Commission > 0 Then

// Convert double to string explictly.
            TotalPayLabel.Text = Commission + Sales

            TotalComm += Commission
        End If

        TotalPayLabel.Text = BASE_RATE
        TotalSales = TotalSales + Sales
        TotalPay = TotalPay + BASE_RATE + Commission
    End Sub

    'Summary Menu Option
    Private Sub SummaryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SummaryToolStripMenuItem.Click
        MessageString = "Total Sales: " &
            TotalSales.ToString("C") &
            Environment.NewLine &
            Environment.NewLine &
            "Total Commission: " &
            TotalComm.ToString("F2")

        MessageBox.Show(MessageString, "Sales Commission Summary",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
    End Sub

    'Exit Menu Option
    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    'Clear Menu Option
    Private Sub ClearToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClearToolStripMenuItem.Click
        EmpNameText.Clear()
        WeeklySalesText.Clear()
        CommissionLabel.Text = ""
        TotalPayLabel.Text = ""

        With EmpNameText.Focus()
        End With
    End Sub

    'Font Menu Option
    Private Sub FontToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles FontToolStripMenuItem.Click
        With FontDialog
            .ShowDialog()
            .Font = TotalPayLabel.Font
            TotalPayLabel.Font = .Font
        End With
    End Sub

    'Color Menu Option
    Private Sub ColorToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ColorToolStripMenuItem.Click
        With ColorDialog
            .ShowDialog()
            .Color = TotalPayLabel.ForeColor
            TotalPayLabel.ForeColor = .Color
        End With
    End Sub

    'About Menu Option
    Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
        MessageBox.Show("Programmed By Kelly Domerstad",
                        "Sales Commission Project",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information)
    End Sub
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote