Efficiency Question

Page 1 of 1

1 Replies - 225 Views - Last Post: 14 September 2012 - 11:27 AM Rate Topic: -----

#1 Bealebe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 09-September 12

Efficiency Question

Posted 14 September 2012 - 11:19 AM

Hey guys!

I have a question about the way I've written my code. The program is working and it does everything I need it to do, But I feel like the way I've done it is inefficient. My problem is pinpointing where I went wrong. Here is my code:


Option Strict On
Public Class frmWorldHungerDonutShop

    Dim gdecChange, gdecTotal, gdecTendered, gdecCoffee, gdecBread As Decimal
    Private Sub subCalculateTotal()
        gdecTotal = (nudQuantity.Value * (gdecCoffee + gdecBread))
        txtTotal.Text = Format(gdecTotal, "currency")
    End Sub
    Private Sub subCalculateChange()
        gdecChange = (-gdecTotal + gdecTendered)
        txtChangeDue.Text = Format(gdecChange, "currency")
    End Sub
    Private Sub subReset()
        nudQuantity.Focus()
        nudQuantity.Value = 1
        radBagels.Checked = False
        radDonuts.Checked = False
        radSandwiches.Checked = False
        txtTotal.Text = "$0.00"
        txtTendered.Text = "$0.00"
        txtChangeDue.Text = "$0.00"
        chkCoffee.Checked = False
    End Sub
    Private Sub frmWorldHungerDonutShop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        nudQuantity.Minimum = 1
        nudQuantity.Maximum = 10
        nudQuantity.Increment = 1
        subReset()
    End Sub
    Private Sub nudQuantity_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudQuantity.ValueChanged
        subCalculateTotal()
        subCalculateChange()
    End Sub
    Private Sub radDonuts_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radDonuts.CheckedChanged
        If radDonuts.Checked Then
            gdecBread = 1
            subCalculateTotal()
            subCalculateChange()
        ElseIf radDonuts.Checked = False Then
            gdecBread = 0
            subCalculateTotal()
            subCalculateChange()
        End If
    End Sub
    Private Sub radBagels_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radBagels.CheckedChanged
        If radBagels.Checked Then
            gdecBread = 2
            subCalculateTotal()
            subCalculateChange()
        ElseIf radBagels.Checked = False Then
            gdecBread = 0
            subCalculateTotal()
            subCalculateChange()
        End If
    End Sub
    Private Sub radSandwiches_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radSandwiches.CheckedChanged
        If radSandwiches.Checked Then
            gdecBread = 3
            subCalculateTotal()
            subCalculateChange()
        ElseIf radSandwiches.Checked = False Then
            gdecBread = 0
            subCalculateTotal()
            subCalculateChange()
        End If
    End Sub
    Private Sub chkCoffee_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCoffee.CheckedChanged
        If chkCoffee.Checked Then
            gdecCoffee = 4
            subCalculateTotal()
            subCalculateChange()
        ElseIf chkCoffee.Checked = False Then
            gdecCoffee = 0
            subCalculateTotal()
            subCalculateChange()
        End if 
    End Sub
    Private Sub txtTotal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTotal.TextChanged
        subCalculateTotal()
    End Sub
    Private Sub txtChangeDue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtChangeDue.TextChanged
        subCalculateChange()
    End Sub

    Private Sub txtTendered_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTendered.TextChanged
        If txtTendered.Focused Then
            gdecTendered = CDec("0" & Format(txtTendered.Text, "standard"))
            subCalculateChange()
        End If
    End Sub
    Private Sub txtTendered_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTendered.LostFocus
        txtTendered.Text = Format(gdecTendered, "currency")
    End Sub
    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        subReset()
    End Sub
    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

End Class



Thank you guys!

Is This A Good Question/Topic? 0
  • +

Replies To: Efficiency Question

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8363
  • View blog
  • Posts: 31,052
  • Joined: 12-June 08

Re: Efficiency Question

Posted 14 September 2012 - 11:27 AM

Please do not create duplicate topics.. closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1