Well, for the whole quarter of my first vb.net class I was on top of the world and breezing through it with not very much trouble. But I guess we fell behind and somehow didn't teach the concept of OOP until 4 days left in the quarter!?!?
So anyway, I am currently working on a project in my book labeled exercise 10B. It says that we must modify a previous form so that it now has a class. In addition with adding the class, the problem wants us to switch the business logic code of the form over to the class. The outcome of the problem doesn't change, just that the calculations for the problem are now in the class instead of the form.
I've been trying this for awhile now and still can't get it and I'm confused becuase I probably missedsomekind of concept because it wasn't explained that well. But now I have finals and I need to get this done because I'm all stressed out. It would be greatly appreciated if some of you guys could point me in the right direction.
The exercise consists of of the following input boxes for the user to fill in.
THE INPUT BOXES
1.salesPersonNameTextBox -it doesn't really play a part in the math.
2.weeklySalesTextBox - this is the textbox in which the user enters their weekly sales.
THE OUTPUT BOXES
1.richTotalPayTextBox - this text box takes the users weekly sales entered and does the equation I'm going to talk about below.
2.commTextBox - This displays the users commission after calculation.
These are the constants.
Const QUOTA_Decimal As Decimal = 1000D
Const COMMISSION_RATE_DecimalAsDecimal=0.15D
Const BASE_PAY_Decimal As Decimal = 250D
If the user makes puts anything >= 1000 in the weeklySalesTextBox its supposed to do the following,
richTotalTextBox = weeklySalesDecimal(the one the user entered) * COMMISSION_RATE_Decimal) + BASE_PAY_Decimal.
If the user enters anything in the weeklySalesTextBox < 1000 then all they get is the base pay and no added commission.
So an example would look like this.
salesPersonNameTextBox: joe joe
weeklySalesTextBox:1000
richTotalTextBox:400
commTextBox:150
Then there's a summary, but that's not important right now.
If I could do it in the form it would be no problem but I'm just really confused. I will first post my code to the form and then the class.
CODE
Public Class salesForm
Private aSalesPerson As SalesPerson
Public weeklySalesOneDecimal As Decimal
Public weeklySalesTwoDecimal As Decimal
Public specialCommDecimal As Decimal
'Declare module level variables for summary infor.
Dim sumTotalPayDecimal, sumTotalDecimal, sumTotalCommDecimal As Decimal
Dim salesCountInteger As Integer
'Declare constants.
Const QUOTA_Decimal As Decimal = 1000D
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const BASE_PAY_Decimal As Decimal = 250D
Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click
'Calculate the total sales, total commission, and total pay.
Dim messageString As String
'confirming the clear by the user'
With Me
.commTextBox.Clear()
.weeklySalesTextBox.Clear()
.richTotalPayTextBox.Clear()
With .salesPersonNameTextBox
.Clear()
.Focus()
'Calculate summary.
If weeklySalesTextBox.Text > 0 Then
messageString = "Weekly Sales: " _
& sumTotalDecimal.ToString("C2") _
& ControlChars.NewLine & ControlChars.NewLine _
& "Total Commissions" & sumTotalCommDecimal.ToString("C2") _
& ControlChars.NewLine & ControlChars.NewLine _
& "Total Pay" & sumTotalPayDecimal.ToString("C2")
MessageBox.Show(messageString, "Total Sales Summary", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
messageString = "No data to summarize."
MessageBox.Show(messageString, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End With
End With
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
'Closing the program.
Me.Close()
End Sub
Private Sub CalculatePayToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculatePayToolStripMenuItem.Click
'Calculate the current amounts and add to the totals.
With Me
Try
If weeklySalesTextBox.Text >= 1000 Then
'Istantiate the SalesPerson object and set the properties.
aSalesPerson = New SalesPerson(.salesPersonNameTextBox.Text, _
Decimal.Parse(.weeklySalesTextBox.Text))
'Calculate and format the results.
.richTotalPayTextBox.Text = aSalesPerson.WeeklySalesOne.ToString("N2")
.commTextBox.Text = aSalesPerson.SpecialComm.ToString("N2")
End If
If weeklySalesTextBox.Text < 1000 Then
aSalesPerson = New SalesPerson(.salesPersonNameTextBox.Text, _
Decimal.Parse(.weeklySalesTextBox.Text))
'Calculate and format the results.
.richTotalPayTextBox.Text = aSalesPerson.WeeklySalesTwo.ToString("N2")
With .commTextBox.Text = " "
End With
End If
Catch quantityExcpetion As FormatException
MessageBox.Show("You must enter a quantity.", "Data entry error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
With Me
.salesPersonNameTextBox.Clear()
.richTotalPayTextBox.Clear()
With .weeklySalesTextBox
.Clear()
.Focus()
End With
End With
End Try
End With
End Sub
Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
'Clear the appropriate controls and display the Yes.NO dialog box.
With Me
.commTextBox.Clear()
.weeklySalesTextBox.Clear()
.richTotalPayTextBox.Clear()
With .salesPersonNameTextBox
.Clear()
.Focus()
End With
End With
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
'Allow the user to change the fonts.
With Me.FontDialog1
.Font = Me.richTotalPayTextBox.Font
.ShowDialog()
Me.richTotalPayTextBox.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 change the colors.
With Me.ColorDialog1
.Color = Me.richTotalPayTextBox.ForeColor
.ShowDialog()
Me.richTotalPayTextBox.ForeColor = .Color
End With
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
'Display the about messageBox.
Dim messageString As String
messageString = "Sales Form" & ControlChars.NewLine _
& ControlChars.NewLine & "Programmed by joe joe"
MessageBox.Show(messageString, "About Sales Form", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
End Class
Now here's my class names SalesPerson.
CODE
Public Class SalesPerson
Const QUOTA_Decimal As Decimal = 1000D
Const COMMISSION_RATE_Decimal As Decimal = 0.15D
Const BASE_PAY_Decimal As Decimal = 250D
Private salesString As String
Private priceTotalDecimal, priceTotalLesserDecimal, specialCommDecimal As Decimal
Private Shared sumTotalDecimal, sumTotalPayDecimal, sumTotalCommDecimal, _
totalSalesDecimal, commDecimal As Decimal
Public weeklySalesOneDecimal, weeklySalesTwoDecimal As Decimal
'Parameterized constructor.
Sub New(ByVal Name As String, ByVal WeeklySalesInput As Decimal)
'Assign the property values.
With Me
.Sales = Sales
.WeeklySalesOne = WeeklySalesOne
.WeeklySalesTwo = WeeklySalesTwo
.SpecialComm = SpecialComm
End With
End Sub
Property Sales() As String
Get
Return salesString
End Get
Set(ByVal value As String)
salesString = value
End Set
End Property
Property WeeklySalesOne() As Decimal
Get
Return weeklySalesOneDecimal
End Get
Set(ByVal value As Decimal)
If value >= 1000 Then
weeklySalesOneDecimal = specialCommDecimal + 250
End If
End Set
End Property
Property SpecialComm() As Decimal
Get
Return specialCommDecimal
End Get
Set(ByVal value As Decimal)
If value >= 1000 Then
specialCommDecimal = weeklySalesOneDecimal * 0.15D
End If
End Set
End Property
Property WeeklySalesTwo() As Decimal
Get
Return weeklySalesTwoDecimal
End Get
Set(ByVal value As Decimal)
If value < 1000 Then
weeklySalesTwoDecimal = BASE_PAY_Decimal
End If
End Set
End Property
End Class
It's probably really easy and once I see it I'll think what took so long, but right now I'm in a world of hurt.