Solved

I need assistance formatting the rest of a Visual Basic project...

Posted on 2011-03-15
5
716 Views
Last Modified: 2012-05-11
My instructor has given us a practice assignment for no grade in order to let us to know what to expect for a future exam, it comes from our textbook "Clearly Visual Basic" pg. 430. A lot of the coding I know and I've attached what I have, but I'd like to see an expert code it so I can truly grasp what to expect from my exam. At least I would like to get some help with the code.

Here's the question:

JM Sales employs eight salespeople. The sales manager wants an application that allows him to enter a bonus rate. The application should use the rate, along with the eight sales amounts stored in an array, to calculate each salesperson's bonus amount. It should also calculate the total bonus paid to the salespeople. The application should display each salesperson's number (1 through 8) and bonus amount, as well as the total bonus paid, in the interface.

Code the application. Use a one-dimensional array whose elements are initialized to the following sales amounts: 2400, 1500, 1600, 2790, 1000, 6300, 1300, and 2700. The txtRate control should accept only numbers, the period, and the Backspace key. The contents of the txtReport control should be cleared when a change is made to the contents of the txtRate control.

Basically, the user types a Bonus rate, clicks create report and the output is a list of Bonuses for each salesperson, 1-8, and the total amount of bonus paid.

I have attached a visual aid of what the interface should look like (which I have no problem creating -- it's the overall code I'd like assistance with), and I wrote my notes as to what I'd name each control. Note the txtReport control is a scrollbox, which is only probably pertinent to my design, but still, I thought you may want to know.

Here is what I have so far:
 
Public Class frmMain
    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click

        ' Declare array

        Dim intSalesAmount() As Integer = {2400, 1500, 1600, 2790, 1000, 6300, 1300, 2700}
        Dim dblTotalBonusPaid As Double = 0

        ' Clear form if not already empty

        txtReport.Text = String.Empty

        ' Prompt if empty txtRate field otherwise get rate and calculate bonus

        If txtRate.Text.Trim() = "" Then
            MessageBox.Show("Please enter rate")
        Else
            Try
                Dim dblRate As Double
                Double.TryParse(txtRate.Text, dblRate)

                txtReport.Text &= vbTab & "Bonus" & vbNewLine
                For index As Integer = 0 To intSalesAmount.Length - 1
                    dblTotalBonusPaid += (dblRate * intSalesAmount(index))
                    txtReport.Text &= (index + 1) & vbTab & (dblRate * intSalesAmount(index)) & vbNewLine
                Next

                txtReport.Text &= vbNewLine & "Total bonus paid: " & String.Format("{0:c}", dblTotalBonusPaid) & vbNewLine

            Catch ex As Exception
                MessageBox.Show("Only Numbers are allowed")
            End Try
        End If
    End Sub
End Class

Open in new window


A couple of problems: I am required to add an additional line of output within the scrollbox that has my class name below "Total Bonus Paid:". And I need to format the list into decimals like in the image. Help would be appreciated.
vbproject.jpg
0
Comment
Question by:pancakesleep
5 Comments
 
LVL 5

Expert Comment

by:Khalid Mehmood Awan
ID: 35144601
This is your assignment, if you seek help from others, Who will be benefited in longer run ? :-)

wait for answers here if you did not get my point.
0
 

Author Comment

by:pancakesleep
ID: 35144617
Well as you can see, I basically have the whole thing coded, so I'm not asking for someone to DO my assignment. I'm asking for help on how to format a couple aspects of it.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35144751
Try something like this out:
Private Sub btnCreate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreate.Click
        ' Declare array
        Dim intSalesAmount() As Integer = {2400, 1500, 1600, 2790, 1000, 6300, 1300, 2700}

        Dim dblRate As Double
        If Double.TryParse(txtRate.Text, dblRate) Then
            Dim bonus As Decimal
            Dim dblTotalBonusPaid As Double = 0
            Dim sb As New System.Text.StringBuilder
            sb.AppendLine("Bonus".PadLeft(15))
            For index As Integer = 0 To intSalesAmount.Length - 1
                bonus = dblRate * intSalesAmount(index)
                sb.AppendLine((index + 1).ToString.PadRight(5) & bonus.ToString("c").PadLeft(10))
                dblTotalBonusPaid += bonus
            Next
            sb.AppendLine("")
            sb.AppendLine("Total bonus paid: " & dblTotalBonusPaid.ToString("c"))
            sb.AppendLine("")
            sb.AppendLine("Your Class Name Here")
            txtReport.Text = sb.ToString
        Else
            MessageBox.Show("Please enter a valid bonus rate.")
            txtRate.Focus()
            txtRate.SelectAll()
        End If
    End Sub

Open in new window

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 35735830
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video teaches viewers about errors in exception handling.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now