Im currently taking a Vb class and am having difficulty writing a function portion of this assignment. is it possible that someone could help me?
A salesperson earns a weekly base salary plus a commission when sales
are at or above quota. Create a project that allows the user to input the
weekly sales and the salesperson name. calculates the commission. and
displays summary information.
Form: The form should have text boxes for the sales person's name and his
or her weekly sales.
Use constants to establish the base pay, the quota, and the commission
rate.
The Pay menu item calculates and displays the commission and the total
pay for that person. However. if there is no commission. do not display
the commission amount (do not display a zero-commission amount).
Write a function procedure to calculate the commission. The function
must compare sales to the quota. When the sales a re equal to or greater
than the quota, calculate the commission by multiplying sales by the
commission rate.
Each sales person receives the base pay plus the commission (if one
has been earned). Formal the dollar amounts to two decimal places; do
not display a dollar sign.
The Summary menu item displays a message box that holds total sales,
total commissions. and total pay for all salespersons. Display the numbers
with two decimal places and dollar signs.
Test Data: Quota = 1000: Commission rate = .15: and Base pay = $250
Please don't use screen shots of code. They're virtually unreadable and, of course completely useless for copying and editing. If there is a relevant piece of code please give it in text, preferably formatted using the tags.
Also please give us the specific problem you are having not just a blanket coverage of the project. If there are errors then please give the full error message and indicate which line it occurs on. If something doesn't do what you expect it to please give the relevant code and both the results you want and the results you get.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
The issue i am having for my project is writing the code and function to calculate information. I have to calculate the commission and the total pay for a sales person. However if there is no commission, do not display the commission amount.
The code I have for this portion is as follows:
Dim SaleDecimal, CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
SaleDecimal = Decimal.Parse(SaleTextBox.Text)
Additionally, i have to write a function that must compare sales to the quote. when the sales are equal to or greater than the quota, calculate the commission by multiplying sales by the commission. The constants are quota = 1000, commission rate .15 and base bay $250. (I'm currently stuck and confused as how to write this out)
For the Function portion of the project I getting the error "Statement is not valid in namespace for the first line"
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesAmountDecimal < QUOTA_Decimal Then
Commission = OD
Elself SalesAmountDecimal <= QUOTA_Decimal Then
Commission(0.15 * SalesDecimal)
Else
Commission()
End If
End Function
Where do you have that function? The error suggests that it is in the wrong place. It appears that it should just be a function in the class, but it also brings up a question as to where the other chunk of code is located.
A couple points, though:
1) Format the code by wrapping it in code tags. You can do this by editing the post, going Advanced, select the code and press the CODE button. Alterantively, you could add the tags by hand with CODE and \CODE, each wrapped in square braces. That will make it look nicer and is easier to read.
2) Decimal.Parse is not the way to convert user input, as it will throw an exception if the value can't be converted. Instead, look into .TryParse, which is the right method, but isn't just a drop in replacement for Parse, as it works differently.
3) In the Commission method you are calling Commission with no argument. That should cause an error unless Commission is overloaded in some odd way. If it is, it probably isn't done on purpose.
EDIT: And right before you call Commission with no arguments, you call it this way:
Commission(0.15 * SalesDecimal)
which ends up being a recursive call that will crash your program in short order when the stack overflows.
1) Format the code by wrapping it in code tags. You can do this by editing the post, going Advanced, select the code and press the CODE button. Alterantively, you could add the tags by hand with CODE and \CODE, each wrapped in square braces. That will make it look nicer and is easier to read.
I am using microsoft visual basic 2010 express and i am not able to do that.
I am using microsoft visual basic 2010 express and i am not able to do that.
The code tags have nothing to do with vb 2010. It has to do with this forum. In your last post there were quote tags. It had QUOTE wrapped with []. Do the same thing with your code:
Code:
CommissionDecimal = SaleDecimal * COMMISSION_RATE_Decimal
PayDecimal = (CommissionDecimal + BasePay_Decimal)
TotalPayDecimal += PayDecimal
CommissionTextBox.Text = CommissionDecimal.ToString("C")
IndPayTextBox.Text = PayDecimal.ToString("C")
PayTextBox.Text = TotalPayDecimal.ToString("C")
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesAmountDecimal < QUOTA_Decimal Then
Commission = OD
Elself SalesAmountDecimal <= QUOTA_Decimal Then
Commission(0.15 * SalesDecimal)
Else
Commission()
End If
End Function
If you're still unsure on how to do that, in the quick reply click on the button to the left of the ABC with the check mark. That generates the quote tags. Replace the word QUOTE with CODE.
Where do you have that function? The error suggests that it is in the wrong place. It appears that it should just be a function in the class, but it also brings up a question as to where the other chunk of code is located.
here is the entire code.
Code:
Public Class SalaryCalcForm
'Decalare module-level variables
Private CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
'Declare constants.
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const QUOTA_Decimal As Decimal = 1000D
Const BasePay_Decimal As Decimal = 250D
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'Display the About message box.
Dim MessageString As String
MessageString = "Salary Calculator" & Environment.NewLine & "Programmed by Andy Wong"
MessageBox.Show(MessageString, "About Salary Calculator", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
'Allow the user to select a new font for the total pay text box.
With FontDialog1
.Font = PayTextBox.Font
.ShowDialog()
PayTextBox.Font = .Font
End With
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
'Allow the user to select a new color for the text of the total pay text box
With ColorDialog1
.ShowDialog()
PayTextBox.ForeColor = .Color
End With
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clears all data input.
SaleTextBox.Clear()
CommissionTextBox.Clear()
PayTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Exits the program
Me.Close()
End Sub
Private Sub PayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PayToolStripMenuItem.Click
'Calculates and displays the commission and the total pay.
Dim SaleDecimal, CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
SaleDecimal = Decimal.Parse(SaleTextBox.Text)
CommissionDecimal = SaleDecimal * COMMISSION_RATE_Decimal
PayDecimal = (CommissionDecimal + BasePay_Decimal)
TotalPayDecimal += PayDecimal
CommissionTextBox.Text = CommissionDecimal.ToString("C")
IndPayTextBox.Text = PayDecimal.ToString("C")
PayTextBox.Text = TotalPayDecimal.ToString("C")
End Sub
End Class
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesAmountDecimal < QUOTA_Decimal Then
Commission = OD
Elself SalesAmountDecimal <= QUOTA_Decimal Then
Commission(0.15 * SalesDecimal)
Else
Commission()
End If
End Function
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
I'm sure you do. Nevertheless that's where End Class belongs. Now you can set about solving the remaining problems.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
Public Class SalaryCalcForm
'Decalare module-level variables
Private CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
'Declare constants.
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const QUOTA_Decimal As Decimal = 1000D
Const BasePay_Decimal As Decimal = 250D
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'Display the About message box.
Dim MessageString As String
MessageString = "Salary Calculator" & Environment.NewLine & "Programmed by Andy Wong"
MessageBox.Show(MessageString, "About Salary Calculator", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
'Allow the user to select a new font for the total pay text box.
With FontDialog1
.Font = PayTextBox.Font
.ShowDialog()
PayTextBox.Font = .Font
End With
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
'Allow the user to select a new color for the text of the total pay text box
With ColorDialog1
.ShowDialog()
PayTextBox.ForeColor = .Color
End With
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clears all data input.
SaleTextBox.Clear()
CommissionTextBox.Clear()
PayTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Exits the program
Me.Close()
End Sub
Private Sub PayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PayToolStripMenuItem.Click
'Calculates and displays the commission and the total pay.
Dim SaleDecimal, CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
SaleDecimal = Decimal.Parse(SaleTextBox.Text)
CommissionDecimal = SaleDecimal * COMMISSION_RATE_Decimal
PayDecimal = (CommissionDecimal + BasePay_Decimal)
TotalPayDecimal += PayDecimal
CommissionTextBox.Text = CommissionDecimal.ToString("C")
IndPayTextBox.Text = PayDecimal.ToString("C")
PayTextBox.Text = TotalPayDecimal.ToString("C")
End Sub
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesAmountDecimal < QUOTA_Decimal Then
Commission = OD
Elself SalesAmountDecimal <= QUOTA_Decimal Then
Commission(0.15 * SalesDecimal)
Else
Commission()
End If
End Function
End Class
notice the end class is on the last line. i get the following errors listed in the picture.
The same thing as in post #2, don't post a screenshot of the error. Copy and paste the error 's you're getting, because I can't even read the descriptions, let alone the file name.
Well, I didn't want to have to go through that trouble... but... for error 1, simply declare SalesDecimalAmount and OD at the form level, removing them where ever else they're declared. Errors 3,4, and 6 should go away when you do that. Error 7, your logic is broken. Commission is a function that returns a decimal, but you're trying to call it as if it's a sub. What I would do is take a look at this site, specifically chapter 10, to get a better understanding of subs vs. functions.
Edit -
By the way, next time you should wrap any errors in code or quote tags... That away it's easier to read for those that want to help.
OD is probably zeroD, where you were trying to enter 0 as a decimal type. That D isn't necessary, since the variable is a Decimal type, so anything in it will also be a Decimal type.
However, the function is pretty thoroughly hosed due to the things I mentioned in #3. Once you fix all the errors, it will do one of two things: Nothing, or crash. You are calling the function itself from within the function in the first else. That's a recursive call, which isn't necessarily bad to do, as long as it ends somewhere, but this one won't. It will keep recursing until the stack overflows. If you had a multiplier greater than 1, it might also exceed the size of Decimal prior to the stack overflowing, but since your multiplier is less than 1, it will converge on zero and crash when the stack overflows.
Furthermore, in the final else, you appear to call the method without an argument, which is what error #7 is talking about. If you gave it an argument, it would still crash, so making the error go away isn't a solution.
Essentially, the function started off well, since you checked for the condition where you should be returning 0, and did. As a general rule, in .NET, people don't return values by assigning them to the name of the method. That was how it was done in classic VB, and it still works in .NET, but people don't do that. Instead, just use the Return statement, so you would just Return 0. After that first check, the rest is problematic. In the first else, I think you wanted to return 1.5 * SalesDecimal, and you just called the method rather than assigning it, which is a good reason to use the Return rather than assigning to the method name.
I'm not sure what you wanted to do with the third condition. I didn't read the problem in sufficient detail I suppose, but I thought that you either got a commission or not. I don't think you even want that Else in there.
There is one other problem. The first condition checks for whether the value is less than the quota, but the second condition also checks whether the value is less than (or equal to) the quota. So, you need to reverse the sign on that one.
IMO you seem to have massively over complicated your solution to the problem.
First off, as the task in hand is purely to take a text input for the salesperson's name and their weekly sales to work out whether or not they get any commission and to display the data.
As it has already been stated, declare all your variables and Consts outside of any function (i.e just below your "Public Class" line and before any other code)
Then have you put your calculate function.
Within the function all you need to do is take the input from the total sales textbox and compare it to the sales quota variable. The key to this is in the task "When the sales are equal to or greater than the quota, calculate the commission by multiplying sales by the commission rate", use either an If statement or a Select Case statement that evaluates this.
This bit is simple, if the total sales is equal to or greater than the sales quota the commission will be the total sales multiplied by the commission rate. If not the commission will be nothing.
It's simple maths being put into logical programming.
I have managed to insert to create the private function but for some reason i am not getting the results i want.
I am supposed to calculate the commission for each person. If there is no commission, do not display the commission amount. Then, write a function procedure to calculate the commission. the function must compare sales to the quota (qutoa=1000). when the sales are equal to or greater than the quota, calculate the commission by multiplying the commission rate (commission rate = .15). Each person receives the base pay plus the commission (if one has been earned). Format the dollar amounts to two decimals and do not display a dollar sign.
i am given the following test data
Sales
1000.00
999.99
2000.00
total should be
$3999.99
450.00
1200.00
Code:
Public Class SalaryCalcForm
'Decalare module-level variables
Private CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
'Declare constants.
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const QUOTA_Decimal As Decimal = 1000D
Const BasePay_Decimal As Decimal = 250D
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'Display the About message box.
Dim MessageString As String
MessageString = "Salary Calculator" & Environment.NewLine & "Programmed by Andy Wong"
MessageBox.Show(MessageString, "About Salary Calculator", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
'Allow the user to select a new font for the total pay text box.
With FontDialog1
.Font = PayTextBox.Font
.ShowDialog()
PayTextBox.Font = .Font
End With
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
'Allow the user to select a new color for the text of the total pay text box
With ColorDialog1
.ShowDialog()
PayTextBox.ForeColor = .Color
End With
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clears all data input.
SaleTextBox.Clear()
CommissionTextBox.Clear()
PayTextBox.Clear()
With NameTextBox
.Clear()
.Focus()
End With
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Exits the program
Me.Close()
End Sub
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesDecimal < QUOTA_Decimal Then
Commission = 0D
ElseIf SalesDecimal >= QUOTA_Decimal Then
Commission = (0.15 * SalesDecimal)
Else : Commission = (0.15 * SalesDecimal)
End If
End Function
Private Sub PayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PayToolStripMenuItem.Click
'Calculates and displays the commission and the total pay.
Dim SaleDecimal, CommissionDecimal, PayDecimal, TotalPayDecimal As Decimal
SaleDecimal = Decimal.Parse(SaleTextBox.Text)
CommissionDecimal = SaleDecimal * COMMISSION_RATE_Decimal
PayDecimal = (CommissionDecimal + BasePay_Decimal)
TotalPayDecimal += PayDecimal
CommissionTextBox.Text = CommissionDecimal.ToString("C")
IndPayTextBox.Text = PayDecimal.ToString("C")
PayTextBox.Text = TotalPayDecimal.ToString("C")
End Sub
End Class
I forgot to clarify on something
the totals should be the following after i have clicked the summary button.
sales $3999.99
commissions 450.00
pay 1200.00
I'm becoming quite desperate in completing this project, I'm willing to pay someone to help me complete this as I can send money through paypal. Please pm me if you are interested.
I made this with buttons instead of menu items. I think it works fine so far, and I'm positive it can be improved a lot (noob here too ) but anyway try to understand what the code is doing. I tried to make it as simple as possible, and like I said, I'm sure it could be done better.
Since you're using VS2008 you can't use auto properties. Change the Seller class to this:
Code:
Public Class Seller
Private _name As String
Public Property Name As String
Get
Return _name
End Get
Set(value As String)
_name = value
End Set
End Property
private _weeklySales As Double
Public Property WeeklySales As Double
Get
Return _weeklySales
End Get
Set(value As Double)
_weeklySales = value
End Set
End Property
Public Overrides Function ToString() As String
Return Me.Name
End Function
End Class
Private Function Commission(ByVal SalesDecimal As Decimal) As Decimal
If SalesAmountDecimal < QUOTA_Decimal Then
Commission = OD
Elself SalesAmountDecimal <= QUOTA_Decimal Then
Commission(0.15 * SalesDecimal)
Else
Commission()
End If
End Function
notice the end class is on the last line. i get the following errors listed in the picture.
As far as I can see you don't have any variable called SalesAmountDecimal.