| | |
Could someone please help me with this logic error??
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 3
Reputation:
Solved Threads: 0
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
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
Please use the [*code] and [/code] tags next time 
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

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 SubThe 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
![]() |
Similar Threads
- Please Hlpe me, lojec erooe (C++)
- Logic error in my code. (C++)
- Logic Error in Java Recursive Method (Java)
- Logic error? (C++)
- Erm, logic error?! (C++)
- Switch logic error (C++)
- Error comparing strings from arrays (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Menu bars and tabs in VB.NET
- Next Thread: Understanding Classes
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





