Running Totals in a Class


May 12, 2005
Programming Experience

attached you will find a link to a program i am working on for school. I have been working on this problem for quite some time now and don't understand why.:(:confused:

When you run the program and start adding items to your order, the grand total does not increment, neither does the tax.

Can anyone help me out with this?
Thanx in advance
Umm from what I can see you don't call any code to perform the new calculations. It would help if you could show where the calculations are performed, because it is a lot of code
When the user hits the Add Shirt Button on the mainForm, the information is passed to a class called ShirtSale. Within ShirtSale, the calculations are done.

Add Shirt Code
Private Sub addShirtButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addShirtButton.Click

			'Allow only 20 items in one order
			If numberTransactionsInteger < 20 Then

			    'Instantiate the StudentBookSale object and set the properties.
			    aShirtSale = New ShirtSale(UCase(customerNameTextBox.Text), _
										   orderNumberTextBox.Text, _
										   Integer.Parse(quantityTextBox.Text), _
										   selectedButtonString, _
										   monogramCheckBox.Checked, _

				'Display Current Order Information
			    totalTaxSummaryLabel.Text = aShirtSale.ItemTax.ToString("C")
			    totalAmountSummaryLabel.Text = aShirtSale.GrandTotal.ToString("C")

				'Add to Array for printing
			    Dim rowInteger, columnInteger As Integer

			    transactionShirtSale(numberTransactionsInteger).sizeString = UCase(aShirtSale.Size)
			    transactionShirtSale(numberTransactionsInteger).extrasString = UCase(aShirtSale.Extras)
			    transactionShirtSale(numberTransactionsInteger).quantityInteger = aShirtSale.Quantity
			    transactionShirtSale(numberTransactionsInteger).itemTotalDecimal = aShirtSale.ItemTotal

			    startOrder = True 'The order has started
			    ' If the order started, disable the customer information
				If startOrder = True Then
				    With customerNameTextBox
					    .Enabled = False
					End With
				    With orderNumberTextBox
					    .Enabled = False
					End With
				    With quantityTextBox
					End With
				    'Enable and Disable form buttons
				    dailySummaryButton.Enabled = False
				    fileDisplaySummaryMenuItem.Enabled = False
				    cancelOrderButton.Enabled = True
				    saleCancelOrderMenuItem.Enabled = True
				    completeButton.Enabled = True
				    saleCompleteMenuItem.Enabled = True
				End If

				'Reset Order Options
				smallRadioButton.Checked = True
				monogramCheckBox.Checked = False
				pocketCheckBox.Checked = False
				numberTransactionsInteger += 1
			    MessageBox.Show("Only 20 Items are allowed", "Overlimit", MessageBoxButtons.OK)
			End If

		Catch ex As Exception When (IsNumeric(customerNameTextBox.Text) = True Or customerNameTextBox.Text = "")
		    MessageBox.Show("Please input a proper CUSTOMER NAME", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
			customerNameTextBox.Enabled = True
			customerNameTextBox.ForeColor = Color.Red
		Catch ex As Exception When (IsNumeric(orderNumberTextBox.Text) = False Or orderNumberTextBox.Text = "")
		    MessageBox.Show("Please input a proper ORDER NUMBER", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
			orderNumberTextBox.Enabled = True
			orderNumberTextBox.ForeColor = Color.Red
		Catch ex As Exception When (IsNumeric(quantityTextBox.Text) = False Or quantityTextBox.Text = "")
		    MessageBox.Show("Please input the proper QUANTITY", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
			quantityTextBox.ForeColor = Color.Red
		End Try
	End Sub

ShirtSale Class
Public Class ShirtSale
	'Declare Input Variables
	Private customerNameString As String
	Private orderNumberString As String
	Private quantityInteger As Integer
	Private sizeSelected As String
	Private Monogram, Pocket As Boolean
	'Declare Flags
	Private sizeFlag As String
	Private extrasFlag As String
	'Declare Constants
	Private Const SMALL_MEDIUM_LARGE_PRICE_Decimal As Decimal = 10D
	Private Const EXTRA_LARGE_PRICE_Decimal As Decimal = 11D
	Private Const XXL_PRICE_Decimal As Decimal = 12D
	Private Const MONOGRAM_PRICE_Decimal As Decimal = 2D
	Private Const POCKET_PRICE_Decimal As Decimal = 1D
	Private Const TAX_Decimal As Decimal = 0.0825D
	'Declare Order Summary and Calculation Variables
	Private itemCounter, itemAmount, taxDecimal, grandTotalDecimal, taxTotal, grandTotalCounter As Decimal
	'Declare Counters
	Private smallCounter, mediumCounter, largeCounter, extraLargeCounter, xxlCounter As Integer
	Private monogramCounter, pocketCounter, noExtrasCounter, bothExtrasCounter As Integer

	'Parameterized Constructor.
	Sub New(ByVal CustomerName As String, ByVal OrderNumber As String, _
	ByVal Quantity As Integer, ByVal ButtonSelected As String, _
	ByVal Mono As Boolean, ByVal Pocket As Boolean)
		'Assign property values.
		Me.customerNameString = CustomerName
		Me.orderNumberString = OrderNumber
		Me.Quantity = Quantity
		Me.sizeSelected = LCase(ButtonSelected)
		Me.Monogram = Mono
		Me.Pocket = Pocket
	End Sub
	Protected Overridable Sub CheckSize()
		'Check the size 
		If sizeSelected = "smallradiobutton" Then
			sizeFlag = "S"
			smallCounter += Quantity
		ElseIf sizeSelected = "mediumradiobutton" Then
			sizeFlag = "M"
			mediumCounter += Quantity
		ElseIf sizeSelected = "largeradiobutton" Then
			sizeFlag = "L"
			largeCounter += Quantity
		ElseIf sizeSelected = "extralargeradiobutton" Then
			sizeFlag = "XL"
			extraLargeCounter += Quantity
		ElseIf sizeSelected = "xxlradiobutton" Then
			sizeFlag = "XXL"
			xxlCounter += Quantity
		End If
	End Sub
	Protected Overridable Sub CheckExtras()
		'Check the extras
		If Monogram = False And Pocket = False Then
			extrasFlag = "NONE"
			noExtrasCounter += Quantity
		ElseIf Monogram = True And Pocket = False Then
			extrasFlag = "M"
			monogramCounter += Quantity
		ElseIf Pocket = True And Monogram = False Then
			extrasFlag = "P"
			pocketCounter += Quantity
		ElseIf (Monogram And Pocket) = True Then
			extrasFlag = "M & P"
			bothExtrasCounter += Quantity
		End If
	End Sub
	Protected Overridable Sub CalculateSale()
		'Calculate the Item Amount
		If sizeFlag = "S" Or sizeFlag = "M" Or sizeFlag = "L" Then
			itemAmount = SMALL_MEDIUM_LARGE_PRICE_Decimal * Quantity
		ElseIf sizeFlag = "XL" Then
			itemAmount = EXTRA_LARGE_PRICE_Decimal * Quantity
		ElseIf sizeFlag = "XXL" Then
			itemAmount = XXL_PRICE_Decimal * Quantity
		End If
		'Calculate the Extra's
		If extrasFlag = "NONE" Then
			itemAmount = itemAmount
		ElseIf extrasFlag = "M" Then
			itemAmount = itemAmount + (MONOGRAM_PRICE_Decimal * Quantity)
		ElseIf extrasFlag = "P" Then
			itemAmount = itemAmount + (POCKET_PRICE_Decimal * Quantity)
		ElseIf extrasFlag = "M & P" Then
		    itemAmount = itemAmount + ((MONOGRAM_PRICE_Decimal * Quantity) + (POCKET_PRICE_Decimal * Quantity))
		End If
		taxDecimal = itemAmount * TAX_Decimal
		grandTotalDecimal = itemAmount + taxDecimal
	End Sub
	Protected Overridable Sub AddToTotals()
		itemCounter += itemAmount
		taxTotal += taxDecimal
		grandTotalCounter += grandTotalDecimal
	End Sub

	ReadOnly Property CustomerName() As String
			Return customerNameString
		End Get
	End Property

	ReadOnly Property OrderNumber() As String
			Return orderNumberString
		End Get
	End Property

	Property Quantity() As Integer
			Return quantityInteger
		End Get
		Set(ByVal Value As Integer)
			If Value >= 0 Then
				quantityInteger = Value
			End If
		End Set
	End Property

	ReadOnly Property Size() As String
			Return sizeFlag
		End Get
	End Property

	ReadOnly Property Extras() As String
			Return extrasFlag
		End Get
	End Property

	ReadOnly Property ItemTotal() As Decimal
			Return itemAmount
		End Get
	End Property

	ReadOnly Property ItemTax() As Decimal
			Return taxTotal
		End Get
	End Property

	ReadOnly Property GrandTotal() As Decimal
			Return grandTotalCounter
		End Get
	End Property
	ReadOnly Property DisplaySmallCounter() As Integer
			Return smallCounter
		End Get
	End Property
	ReadOnly Property DisplayMediumCounter() As Integer
			Return mediumCounter
		End Get
	End Property
	ReadOnly Property DisplayLargeCounter() As Integer
			Return largeCounter
		End Get
	End Property
	ReadOnly Property DisplayXLCounter() As Integer
			Return extraLargeCounter
		End Get
	End Property
	ReadOnly Property DisplayXXLCounter() As Integer
			Return xxlCounter
		End Get
	End Property
	ReadOnly Property DisplayMonogramCounter() As Integer
			Return monogramCounter
		End Get
	End Property
	ReadOnly Property DisplayPocketCounter() As Integer
			Return pocketCounter
		End Get
	End Property
	ReadOnly Property DisplayNoExtrasCounter() As Integer
			Return noExtrasCounter
		End Get
	End Property
	ReadOnly Property DisplayBothExtrasCounter() As Integer
			Return bothExtrasCounter
		End Get
	End Property


	Public Overridable Sub ResetCalcs()
		itemAmount = 0
		taxDecimal = 0
		grandTotalDecimal = 0
	End Sub

	Public Overridable Sub ResetCounters()
		smallCounter = 0
		mediumCounter = 0
		largeCounter = 0
		extraLargeCounter = 0
		xxlCounter = 0
		monogramCounter = 0
		pocketCounter = 0
		bothExtrasCounter = 0
		noExtrasCounter = 0
	End Sub
End Class
I’m sorry that I’m the one to tell you this, but your project seems like a simple one, with clear requirements and specifications. Then, do you need OOP model?

Maybe your instructor required you but in my opinion it can be accomplished (certain task/s) with far less code and without OO Programming. Think about that or ask your instructor for advice and tell me if you need a help ... looking forward to hear from you soon ... Cheers :)
You are on the nose. My instructor wanted us to use OOP, i have the same project with out OOP and works just fine. But i need it to work with OOP.

And your not offensive at all.

Hahaha ... of course i knew it that your instructor is that one who wants OOP ;) ... that's happen all the time ... but you could ask your instructor "WHY OOP for this PROJECT?" It really doesn't make any sense, at least not to me. I'm glad to discuss or elaborate if you'd like.

However, i will try to help you out ... just give me some time to take a look of your code

Cheers :)