Payroll Program help needed

bigboywasim

Member
Joined
Sep 29, 2006
Messages
18
Programming Experience
Beginner
VB.NET:
Dim decSellingPrice As Decimal
Dim decCost As Decimal
Dim decProfit As Decimal
Dim decLoss As Decimal

If there is a loss, the Profit or Loss BackColor is red and its ForeColor is white. If there is a Profit, the BackColor is light-grey and the ForeColor is Black.The Commission BackColor is light-grey and the ForeColor is black.The Calculate button, calculates the Profit or Loss by subtracting the cost from the selling price. Use the FormatCurrency() function to display Profit or Loss. The Commission is calculated by multiply 0.2D times the Profit or Loss. If there is a Loss, the Commission is set to $0.00.Use the FormatCurrency() function to display theCommission. You MUST use a constant which will contain 0.2D.

I just started to learn how to program and I need some help. I have the logic somewhat down but I don't know how to program that well. Please help and thank you. I posted this in the other forum but this one is more active so I posted here as well. I hope that is ok.
progress.gif
 
Last edited by a moderator:
Firstly, no duplicate threads please. One topic per thread and one thread per topic, in the most appropriate forum. If you post incorrectly please PM a mod to move it. Your other thread has been deleted.

Secondly, we don't do people's homework for them. You've simply posted the spec and said "help". That's not going to cut it. You need to make a start and show that you're making an effort or ask a specific question that indicates what you're having an issue with. If you're just not very good then that's why you're taking a class. If you have no idea whatsoever then you should go and have a word to your teacher. if you do have an idea then show us. Then we'll gladly help you move in the right direction, but it's up to you to do the work. You'll find people here, including myself, will be very helpful, but we're here to help YOU become a better programmer. To do that YOU have to program.
 
I think I got the color change part down. The commission color is the normal color set in design view. If I can do anything to make it better you guys are more than welcome to tell me. When I will have the calculation part done I will post that as well.

VB.NET:
If (lblProfitorLoss.Text = decProfit & Not 0) Then
lblProfitorLoss.BackColor = Color.LightGray
Else
lblProfitorLoss.BackColor = Color.Red
EndIf
 
If (lblProfitorLoss.Text = decProfit & Not 0) Then
lblProfitorLoss.ForeColor = Color.Black
Else
lblProfitorLoss.ForeColor = Color.White
EndIf
 
Last edited by a moderator:
VB.NET:
decSellingPrice = CDec(txtSellingPrice.Text)
decCost = CDec(txtCostValue.Text)
decProfit = CDec(lblProfitorLoss.Text > 0)
decLoss = CDec(lblProfitorLoss.Text < 0)
lblProfitorLoss.Text = FormatCurrency(CDec(decSellingPrice - decCost))
lblCommission.Text = FormatCurrency(CDec(decProfit Or decLoss) * 0.2D)
This is the best I can do for the calculation part. There are still some errors in it.
Please help me with this.
 
Last edited by a moderator:
OK guys I think I have it but I need an even handler and I do not know how to do it.

Something like this

VB.NET:
AddHandler Me.button1.Click, AddressOf Me.Button1Click
Then I code the subroutine that the button click event points to, something like this -

VB.NET:
Private Sub Button1Click(sender As System.Object, e As System.EventArgs)
I get an error under AddHandler it says syntax error and I can't do the Private Sub Button1Click because it is already under the color part of the code. Please help me out with the event handler and what part of my code I put it in.

Here is how my code looks like now

VB.NET:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
 
 
Dim decSellingPrice As Decimal
Dim decCost As Decimal
Dim decProfit As Decimal
Dim decLoss As Decimal
 
If (lblProfitorLoss.Text = decProfit & Not 0) Then
lblProfitorLoss.BackColor = Color.LightGray
lblProfitorLoss.ForeColor = Color.Black
Else
lblProfitorLoss.BackColor = Color.Red
lblProfitorLoss.ForeColor = Color.White
End If
 
 
End Sub
 
 
Public Sub CalcProfitLoss()
Dim decSellingPrice As Decimal
Dim decCost As Decimal
Dim decProfit As Decimal
Dim decLoss As Decimal
If decSellingPrice - decCost > 0 Then
decProfit = decSellingPrice - decCost
lblProfitorLoss.Text = FormatCurrency(decProfit, 2)
lblCommission.Text = FormatCurrency(CalcCom(decProfit), 2)
Else
decLoss = decSellingPrice - decCost
lblProfitorLoss.Text = FormatCurrency(decLoss, 2)
lblCommission.Text = FormatCurrency(CalcCom(decLoss), 2)
End If
End Sub
 
 
Public Function CalcCom(ByVal Amount As Double) As Double
Const CommRate As Double = 0.2
If Amount * CommRate > 0 Then
Return Amount * CommRate
Else
Return 0
End If
End Function
 
Last edited by a moderator:
You shouldn't be using AddHandler if you've created the button in the designer. Just double-click the button in the design window to automatically generate a handler for its default event, which is Click. You can also create event handlers via the Properties window or the code window. You only need to use AddHandler for controls you create at run time or if you need to change a control's event handler at run time.
 
Ok thanks guys I got it after so much trial and error. I guess this is how this programming stuff works.

VB.NET:
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
 
Dim decSellingPrice As Decimal
Dim decCost As Decimal
Dim decProfit As Decimal
Dim decLoss As Decimal
decSellingPrice = CDec(txtSellingPrice.Text)
decCost = CDec(txtCostValue.Text)
If decSellingPrice - decCost > 0 Then
decProfit = decSellingPrice - decCost
lblProfitorLoss.Text = FormatCurrency(decProfit)
lblCommission.Text = FormatCurrency((decProfit) * 2D)
Else
decLoss = decSellingPrice - decCost
lblProfitorLoss.Text = FormatCurrency(decLoss)
lblCommission.Text = FormatCurrency((decLoss) * 0)
End If
If decSellingPrice - decCost < 0 Then
lblProfitorLoss.BackColor = Color.Red
lblProfitorLoss.ForeColor = Color.White
End If
 
Back
Top