944,124 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4263
  • VB.NET RSS
Feb 23rd, 2005
0

Could someone please help me with this logic error??

Expand Post »
The project should display a different amount if the new release check box and the dvd {or vhs} radio button are both checked, its displaying the regular price.

This is my code:

Option Strict On

Public Class videoBonanzaSaleForm
Inherits System.Windows.Forms.Form

' Declare Constants
Const DVD_PRICE_Decimal As Decimal = 2.5D
Const NEW_RELEASE_DVD_Decimal As Decimal = 3D
Const VHS_PRICE_Decimal As Decimal = 1.8D
Const NEW_RELEASE_VHS_Decimal As Decimal = 2D
Const DISCOUNT_RATE_Decimal As Decimal = 0.1D

' Declare module-level variables.
Dim customerCountInteger As Integer
Dim grandTotalDecimal, totalDecimal, itemAmountDecimal As Decimal


Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Calculate and display the current amounts.

Dim priceDecimal, discountDecimal As Decimal

If titleTextBox.Text <> "" Then

If dvdRadioButton.Checked = True Or vhsRadioButton.Checked = True Then

' Find the price.
If dvdRadioButton.Checked Then
priceDecimal = DVD_PRICE_Decimal
ElseIf vhsRadioButton.Checked Then
priceDecimal = VHS_PRICE_Decimal
ElseIf newReleaseCheckBox.Checked And dvdRadioButton.Checked Then
priceDecimal = NEW_RELEASE_DVD_Decimal
ElseIf newReleaseCheckBox.Checked And vhsRadioButton.Checked Then
priceDecimal = NEW_RELEASE_VHS_Decimal
End If

' Calculate the extended price and add to order total.
If memberCheckBox.Checked Then
discountDecimal = priceDecimal * DISCOUNT_RATE_Decimal
Else
discountDecimal = 0
End If

itemAmountDecimal = priceDecimal - discountDecimal
totalDecimal += itemAmountDecimal

itemAmountLabel.Text = itemAmountDecimal.ToString("C")
totalLabel.Text = totalDecimal.ToString("C")
Else
MessageBox.Show("A Movies Format Must Be Selected", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Else
MessageBox.Show("A Title Must Be Entered.", "Data Enrty Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
titleTextBox.Focus()
End If

' Allow a change only for a new order.
memberCheckBox.Enabled = False

' Allow clear after an order has begun.
clearButton.Enabled = True

' Reset format Radio Buttons and clear text box.
vhsRadioButton.Checked = False
dvdRadioButton.Checked = False
titleTextBox.Clear()

End Sub
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Richie is offline Offline
3 posts
since Oct 2004
Mar 10th, 2005
0

Re: Could someone please help me with this logic error??

Please use the [*code] and [/code] tags next time

Option Strict On

Public Class videoBonanzaSaleForm
Inherits System.Windows.Forms.Form

' Declare Constants
Const DVD_PRICE_Decimal As Decimal = 2.5D
Const NEW_RELEASE_DVD_Decimal As Decimal = 3D
Const VHS_PRICE_Decimal As Decimal = 1.8D
Const NEW_RELEASE_VHS_Decimal As Decimal = 2D
Const DISCOUNT_RATE_Decimal As Decimal = 0.1D

' Declare module-level variables.
Dim customerCountInteger As Integer
Dim grandTotalDecimal, totalDecimal, itemAmountDecimal As Decimal


Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
	' Calculate and display the current amounts.

	Dim priceDecimal, discountDecimal As Decimal

	If titleTextBox.Text <> "" Then

		If dvdRadioButton.Checked = True Or vhsRadioButton.Checked = True Then

			' Find the price.
			If dvdRadioButton.Checked Then
				If newReleaseCheckBox.Checked Then
					priceDecimal = NEW_RELEASE_DVD_Decimal
				Else
					priceDecimal = DVD_PRICE_Decimal
				End If
			ElseIf vhsRadioButton.Checked Then
				If newReleaseCheckBox.Checked Then
					priceDecimal = NEW_RELEASE_VHS_Decimal
				Else
					priceDecimal = VHS_PRICE_Decimal
				End If
			End If 

			' Calculate the extended price and add to order total.
			If memberCheckBox.Checked Then
				discountDecimal = priceDecimal * DISCOUNT_RATE_Decimal
			Else
				discountDecimal = 0
			End If

			itemAmountDecimal = priceDecimal - discountDecimal
			totalDecimal += itemAmountDecimal

			itemAmountLabel.Text = itemAmountDecimal.ToString("C")
			totalLabel.Text = totalDecimal.ToString("C")
		Else
			MessageBox.Show("A Movies Format Must Be Selected", "Data Entry Error", _
			MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If
	Else
		MessageBox.Show("A Title Must Be Entered.", "Data Enrty Error", _
		MessageBoxButtons.OK, MessageBoxIcon.Error)
		titleTextBox.Focus()
	End If

	' Allow a change only for a new order.
	memberCheckBox.Enabled = False

	' Allow clear after an order has begun.
	clearButton.Enabled = True

	' Reset format Radio Buttons and clear text box.
	vhsRadioButton.Checked = False
	dvdRadioButton.Checked = False
	titleTextBox.Clear()

End Sub

The part I changed is in bold.
The problem was you were saying it like this:

1.IF It's a DVD or VHS THEN
1a. IF It's a DVD THEN
1a1. Set the it to regular DVD
1b. IF it's a VHS THEN
1b1. Set it to a regular VHS
1c. IF It's a New DVD
1c1. Then Set it to new dvd
1d. IF It's a new VHS THEN
1d1. Set it to a new VHS
2. END IF

Let's say a customer choose New Release VHS.
The computer would read through those instructions like this:
1. = True
1a. = False
1b. = True
1b1. it would set the value here
2.

You were thinking it would go like this:
1. = true
1a. = false
1b. = true
1b1. set the value
1c = false
1d = true
1d1. re set the value
2

Hope this helps explain it a bit
Reputation Points: 46
Solved Threads: 2
Junior Poster
Iron_Cross is offline Offline
117 posts
since Jul 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Menu bars and tabs in VB.NET
Next Thread in VB.NET Forum Timeline: Understanding Classes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC