UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
November
Su M Tu W Th F Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Sponsored Links
Latest Postings
Latest Reviews
Topic Options
Rate This Topic
#17855 - 11/06/03 03:28 AM Whats Wrong with this program?
Chem Offline
UGN News Staff

Registered: 10/13/02
Posts: 364
Loc: Vagabond (Location Differs)
Basically, coded a program for class, I think I made a few mistakes, and possibly some sloppy coding,

Please point out any mistakes I might have made,
and also I suck at pseudocode, so feel free to help out.

Code:
 Option Strict On

Public Class frmAuto
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents grpAccessories As System.Windows.Forms.GroupBox
    Friend WithEvents grpFinish As System.Windows.Forms.GroupBox
    Friend WithEvents btnCalculate As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents chkStereo As System.Windows.Forms.CheckBox
    Friend WithEvents chkLeather As System.Windows.Forms.CheckBox
    Friend WithEvents radStandard As System.Windows.Forms.RadioButton
    Friend WithEvents radPearlized As System.Windows.Forms.RadioButton
    Friend WithEvents radCustom As System.Windows.Forms.RadioButton
    Friend WithEvents lblAccessoriesAndFinish As System.Windows.Forms.Label
    Friend WithEvents lblSalesTax As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents lblSubtotal As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents lblAmountDue As System.Windows.Forms.Label
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents txtSalesPrice As System.Windows.Forms.TextBox
    Friend WithEvents txtTradeIn As System.Windows.Forms.TextBox
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents chkNavigation As System.Windows.Forms.CheckBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.grpAccessories = New System.Windows.Forms.GroupBox()
        Me.chkNavigation = New System.Windows.Forms.CheckBox()
        Me.chkLeather = New System.Windows.Forms.CheckBox()
        Me.chkStereo = New System.Windows.Forms.CheckBox()
        Me.grpFinish = New System.Windows.Forms.GroupBox()
        Me.radCustom = New System.Windows.Forms.RadioButton()
        Me.radPearlized = New System.Windows.Forms.RadioButton()
        Me.radStandard = New System.Windows.Forms.RadioButton()
        Me.btnCalculate = New System.Windows.Forms.Button()
        Me.btnClear = New System.Windows.Forms.Button()
        Me.btnExit = New System.Windows.Forms.Button()
        Me.lblAccessoriesAndFinish = New System.Windows.Forms.Label()
        Me.lblSalesTax = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.lblSubtotal = New System.Windows.Forms.Label()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.Label6 = New System.Windows.Forms.Label()
        Me.lblAmountDue = New System.Windows.Forms.Label()
        Me.Label8 = New System.Windows.Forms.Label()
        Me.Label9 = New System.Windows.Forms.Label()
        Me.Label10 = New System.Windows.Forms.Label()
        Me.txtSalesPrice = New System.Windows.Forms.TextBox()
        Me.txtTradeIn = New System.Windows.Forms.TextBox()
        Me.grpAccessories.SuspendLayout()
        Me.grpFinish.SuspendLayout()
        Me.SuspendLayout()
        '
        'grpAccessories
        '
        Me.grpAccessories.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkNavigation, Me.chkLeather, Me.chkStereo})
        Me.grpAccessories.Location = New System.Drawing.Point(8, 16)
        Me.grpAccessories.Name = "grpAccessories"
        Me.grpAccessories.Size = New System.Drawing.Size(168, 112)
        Me.grpAccessories.TabIndex = 0
        Me.grpAccessories.TabStop = False
        Me.grpAccessories.Text = "Accessories"
        '
        'chkNavigation
        '
        Me.chkNavigation.Location = New System.Drawing.Point(16, 80)
        Me.chkNavigation.Name = "chkNavigation"
        Me.chkNavigation.Size = New System.Drawing.Size(144, 24)
        Me.chkNavigation.TabIndex = 2
        Me.chkNavigation.Text = "&Computer Navigation"
        '
        'chkLeather
        '
        Me.chkLeather.Location = New System.Drawing.Point(16, 48)
        Me.chkLeather.Name = "chkLeather"
        Me.chkLeather.Size = New System.Drawing.Size(112, 24)
        Me.chkLeather.TabIndex = 1
        Me.chkLeather.Text = "Leather &Interior"
        '
        'chkStereo
        '
        Me.chkStereo.Location = New System.Drawing.Point(16, 16)
        Me.chkStereo.Name = "chkStereo"
        Me.chkStereo.Size = New System.Drawing.Size(112, 24)
        Me.chkStereo.TabIndex = 0
        Me.chkStereo.Text = "&Stereo System"
        '
        'grpFinish
        '
        Me.grpFinish.Controls.AddRange(New System.Windows.Forms.Control() {Me.radCustom, Me.radPearlized, Me.radStandard})
        Me.grpFinish.Location = New System.Drawing.Point(8, 152)
        Me.grpFinish.Name = "grpFinish"
        Me.grpFinish.Size = New System.Drawing.Size(168, 120)
        Me.grpFinish.TabIndex = 1
        Me.grpFinish.TabStop = False
        Me.grpFinish.Text = "Exterior Finish"
        '
        'radCustom
        '
        Me.radCustom.Location = New System.Drawing.Point(16, 88)
        Me.radCustom.Name = "radCustom"
        Me.radCustom.Size = New System.Drawing.Size(144, 24)
        Me.radCustom.TabIndex = 2
        Me.radCustom.Text = "Customized &Detailing"
        '
        'radPearlized
        '
        Me.radPearlized.Location = New System.Drawing.Point(16, 56)
        Me.radPearlized.Name = "radPearlized"
        Me.radPearlized.TabIndex = 1
        Me.radPearlized.Text = "&Pearlized"
        '
        'radStandard
        '
        Me.radStandard.Checked = True
        Me.radStandard.Location = New System.Drawing.Point(16, 24)
        Me.radStandard.Name = "radStandard"
        Me.radStandard.TabIndex = 0
        Me.radStandard.TabStop = True
        Me.radStandard.Text = "S&tandard"
        '
        'btnCalculate
        '
        Me.btnCalculate.Location = New System.Drawing.Point(96, 304)
        Me.btnCalculate.Name = "btnCalculate"
        Me.btnCalculate.Size = New System.Drawing.Size(75, 32)
        Me.btnCalculate.TabIndex = 6
        Me.btnCalculate.Text = "&Calculate"
        '
        'btnClear
        '
        Me.btnClear.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnClear.Location = New System.Drawing.Point(216, 304)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(75, 32)
        Me.btnClear.TabIndex = 7
        Me.btnClear.Text = "C&lear"
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(328, 304)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(75, 32)
        Me.btnExit.TabIndex = 8
        Me.btnExit.Text = "E&xit"
        '
        'lblAccessoriesAndFinish
        '
        Me.lblAccessoriesAndFinish.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblAccessoriesAndFinish.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.lblAccessoriesAndFinish.Location = New System.Drawing.Point(344, 80)
        Me.lblAccessoriesAndFinish.Name = "lblAccessoriesAndFinish"
        Me.lblAccessoriesAndFinish.TabIndex = 10
        Me.lblAccessoriesAndFinish.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblSalesTax
        '
        Me.lblSalesTax.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblSalesTax.Location = New System.Drawing.Point(344, 120)
        Me.lblSalesTax.Name = "lblSalesTax"
        Me.lblSalesTax.TabIndex = 12
        Me.lblSalesTax.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(224, 16)
        Me.Label3.Name = "Label3"
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "C&ar Sales Price"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblSubtotal
        '
        Me.lblSubtotal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblSubtotal.Location = New System.Drawing.Point(344, 160)
        Me.lblSubtotal.Name = "lblSubtotal"
        Me.lblSubtotal.TabIndex = 14
        Me.lblSubtotal.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(212, 80)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(112, 23)
        Me.Label5.TabIndex = 9
        Me.Label5.Text = "Accessories && Finish:"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(224, 160)
        Me.Label6.Name = "Label6"
        Me.Label6.TabIndex = 13
        Me.Label6.Text = "Subtotal:"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'lblAmountDue
        '
        Me.lblAmountDue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblAmountDue.Location = New System.Drawing.Point(344, 240)
        Me.lblAmountDue.Name = "lblAmountDue"
        Me.lblAmountDue.TabIndex = 16
        Me.lblAmountDue.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(224, 240)
        Me.Label8.Name = "Label8"
        Me.Label8.TabIndex = 15
        Me.Label8.Text = "Amount Due:"
        Me.Label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(220, 200)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(104, 23)
        Me.Label9.TabIndex = 4
        Me.Label9.Text = "T&rade-in Allowance:"
        Me.Label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(224, 120)
        Me.Label10.Name = "Label10"
        Me.Label10.TabIndex = 11
        Me.Label10.Text = "Sales Tax (8%):"
        Me.Label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'txtSalesPrice
        '
        Me.txtSalesPrice.Location = New System.Drawing.Point(344, 16)
        Me.txtSalesPrice.Name = "txtSalesPrice"
        Me.txtSalesPrice.TabIndex = 3
        Me.txtSalesPrice.Text = ""
        Me.txtSalesPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'txtTradeIn
        '
        Me.txtTradeIn.Location = New System.Drawing.Point(344, 200)
        Me.txtTradeIn.Name = "txtTradeIn"
        Me.txtTradeIn.TabIndex = 5
        Me.txtTradeIn.Text = ""
        Me.txtTradeIn.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
        '
        'frmAuto
        '
        Me.AcceptButton = Me.btnCalculate
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.CancelButton = Me.btnClear
        Me.ClientSize = New System.Drawing.Size(504, 349)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtTradeIn, Me.txtSalesPrice, Me.Label10, Me.Label9, Me.Label8, Me.lblAmountDue, Me.Label6, Me.Label5, Me.lblSubtotal, Me.Label3, Me.lblSalesTax, Me.lblAccessoriesAndFinish, Me.btnExit, Me.btnClear, Me.btnCalculate, Me.grpAccessories, Me.grpFinish})
        Me.Name = "frmAuto"
        Me.Text = "VB Auto Center"
        Me.grpAccessories.ResumeLayout(False)
        Me.grpFinish.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region
    Const mdecSTEREO_CHARGE As Decimal = 425.76D
    Const mdecLEATHER_CHARGE As Decimal = 987.41D
    Const mdecCOMPUTER_CHARGE As Decimal = 1741.23D
    Const mdecPEARLIZED_CHARGE As Decimal = 345.72D
    Const mdecDETAILING_CHARGE As Decimal = 599.99D
    Const mdecTAX_RATE As Decimal = 0.08D

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
        'Exits the aplication
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Calculate price
        Dim decAmountDue As Decimal
        Dim decSubTotal As Decimal
        Dim decTax As Decimal
        Dim decSalesPrice As Decimal
        Dim decAllowance As Decimal
        Dim decAccTotal As Decimal
        Dim strMessage As String


        'If no data was entered into the trade-in text box, default the amount to zero
        If txtTradeIn.Text = "" Then
            txtTradeIn.Text = "0"
        End If

        If txtSalesPrice.Text = "" Then
            MessageBox.Show("Please enter the sale amount.", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtSalesPrice.Focus()
        Else
            Try 'Calculate the totals

                decSalesPrice = CDec(txtSalesPrice.Text)
                decAllowance = CDec(txtTradeIn.Text)

                'Test the option buttons for added charges
                If radPearlized.Checked = True Then
                    decAccTotal = mdecPEARLIZED_CHARGE
                ElseIf radCustom.Checked = True Then
                    decAccTotal += mdecDETAILING_CHARGE
                End If

                'Test the check boxes
                If chkStereo.Checked = False Then
                    decAccTotal += mdecSTEREO_CHARGE
                End If
                If chkLeather.Checked = True Then
                    decAccTotal += mdecLEATHER_CHARGE
                End If
                If chkNavigation.Checked = True Then
                    decAccTotal += mdecCOMPUTER_CHARGE
                End If

                'Calculate sales tax
                decTax = (decSalesPrice + decAccTotal) * mdecTAX_RATE
                'Calculate subtotal
                decSubTotal = decSalesPrice + decAccTotal - decTax
                'Calculate amount due
                decAmountDue = decSubTotal - decAllowance

                'Display amounts in labels
                txtSalesPrice.Text = FormatCurrency(decSalesPrice)
                lblAccessoriesAndFinish.Text = FormatCurrency(decAccTotal)
                lblSalesTax.Text = FormatCurrency(decTax)
                lblSubtotal.Text = FormatCurrency(decSubTotal)
                txtTradeIn.Text = FormatCurrency(txtTradeIn.Text)
                lblAmountDue.Text = FormatCurrency(decAmountDue)
            Catch
                strMessage = "Calculation error"
                MessageBox.Show(strMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'Clear the screen and restores focus to the first field

        txtSalesPrice.Text = ""
        txtTradeIn.Text = ""
        lblAccessoriesAndFinish.Text() = ""
        lblSalesTax.Text() = ""
        lblSubtotal.Text() = ""
        lblAmountDue.Text() = ""
        txtSalesPrice.Focus()
    End Sub
End Class
_________________________
C++ Should Have Been Called "D"

Top
Sponsored Links
      
#17856 - 11/06/03 03:34 AM Re: Whats Wrong with this program?
Chem Offline
UGN News Staff

Registered: 10/13/02
Posts: 364
Loc: Vagabond (Location Differs)
Here it is, minus the form generated code:

Option Strict On

Public Class frmAuto

Inherits System.Windows.Forms.Form

[windows form designer generated code]

Const mdecSTEREO_CHARGE As Decimal = 425.76D
Const mdecLEATHER_CHARGE As Decimal = 987.41D
Const mdecCOMPUTER_CHARGE As Decimal = 1741.23D
Const mdecPEARLIZED_CHARGE As Decimal = 345.72D
Const mdecDETAILING_CHARGE As Decimal = 599.99D
Const mdecTAX_RATE As Decimal = 0.08D

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
'Exits the aplication
End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Calculate price
Dim decAmountDue As Decimal
Dim decSubTotal As Decimal
Dim decTax As Decimal
Dim decSalesPrice As Decimal
Dim decAllowance As Decimal
Dim decAccTotal As Decimal
Dim strMessage As String


'If no data was entered into the trade-in text box, default the amount to zero
If txtTradeIn.Text = "" Then
txtTradeIn.Text = "0"
End If

If txtSalesPrice.Text = "" Then
MessageBox.Show("Please enter the sale amount.", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtSalesPrice.Focus()
Else
Try 'Calculate the totals

decSalesPrice = CDec(txtSalesPrice.Text)
decAllowance = CDec(txtTradeIn.Text)

'Test the option buttons for added charges
If radPearlized.Checked = True Then
decAccTotal = mdecPEARLIZED_CHARGE
ElseIf radCustom.Checked = True Then
decAccTotal += mdecDETAILING_CHARGE
End If

'Test the check boxes
If chkStereo.Checked = False Then
decAccTotal += mdecSTEREO_CHARGE
End If
If chkLeather.Checked = True Then
decAccTotal += mdecLEATHER_CHARGE
End If
If chkNavigation.Checked = True Then
decAccTotal += mdecCOMPUTER_CHARGE
End If

'Calculate sales tax
decTax = (decSalesPrice + decAccTotal) * mdecTAX_RATE
'Calculate subtotal
decSubTotal = decSalesPrice + decAccTotal - decTax
'Calculate amount due
decAmountDue = decSubTotal - decAllowance

'Display amounts in labels
txtSalesPrice.Text = FormatCurrency(decSalesPrice)
lblAccessoriesAndFinish.Text = FormatCurrency(decAccTotal)
lblSalesTax.Text = FormatCurrency(decTax)
lblSubtotal.Text = FormatCurrency(decSubTotal)
txtTradeIn.Text = FormatCurrency(txtTradeIn.Text)
lblAmountDue.Text = FormatCurrency(decAmountDue)
Catch
strMessage = "Calculation error"
MessageBox.Show(strMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
'Clear the screen and restores focus to the first field

txtSalesPrice.Text = ""
txtTradeIn.Text = ""
lblAccessoriesAndFinish.Text() = ""
lblSalesTax.Text() = ""
lblSubtotal.Text() = ""
lblAmountDue.Text() = ""
txtSalesPrice.Focus()
End Sub
End Class
_________________________
C++ Should Have Been Called "D"

Top
#17857 - 04/29/04 12:21 PM Re: Whats Wrong with this program?
spaceman Offline
Junior Member

Registered: 04/29/04
Posts: 11
Loc: south africa
can you just end try like that?
don't you need a catch block?
_________________________
please don't read this, if u do i will dissapea.....

Top

Featured Member
Registered: 08/22/14
Posts: 1
Forum Stats
2151 Members
46 Forums
35784 Topics
70954 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 28945
Gremelin 7193
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
HushHush, golqm, Tim050, Gecko666, defghi795767
2150 Registered Users
Who's Online
0 registered (), 469 Guests and 303 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!