7 Replies - 667 Views - Last Post: 14 September 2012 - 12:07 PM 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 - 08:22 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 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5595
  • View blog
  • Posts: 11,970
  • Joined: 02-June 10

Re: Efficiency Question

Posted 14 September 2012 - 11:15 AM

You're in VB6 - so right there 'efficiency' is a relative term.
VB6 is considered dead for new projects and really only used for support of legacy applications.

Had you considered moving up to VB.NET so you can take advantage of all the new stuff made in the last 15 years?

Or is this really a VB.NET solution placed in the wrong forum?
Was This Post Helpful? 1
  • +
  • -

#3 Bealebe  Icon User is offline

  • New D.I.C Head

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

Re: Efficiency Question

Posted 14 September 2012 - 11:16 AM

probably the latter....

My bad I'll move it!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9426
  • View blog
  • Posts: 35,422
  • Joined: 12-June 08

Re: Efficiency Question

Posted 14 September 2012 - 11:26 AM

Moving the post to VB.NET (from vb6).

OP - For future reference - if you need a most moved click the 'report' button and write in where you need it to go.

This post has been edited by modi123_1: 14 September 2012 - 12:06 PM

Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5365
  • View blog
  • Posts: 27,329
  • Joined: 10-May 07

Re: Efficiency Question

Posted 14 September 2012 - 11:27 AM

View PosttlhIn`toq, on 14 September 2012 - 02:15 PM, said:

You're in VB6 - so right there 'efficiency' is a relative term.

I was thinking this same thing when reading the title.

"This is as good as it gets.... in 1998"
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5595
  • View blog
  • Posts: 11,970
  • Joined: 02-June 10

Re: Efficiency Question

Posted 14 September 2012 - 12:04 PM

View Postmodi123_1, on 14 September 2012 - 12:26 PM, said:

For future reference - if you need a most moved click the 'report' button and write in where you need it to go.


Being a C# guy I don't really recognize the differences in VB6 and VB.NET well enough to be sure. That's why I ask the OP if they *meant* VB6.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9426
  • View blog
  • Posts: 35,422
  • Joined: 12-June 08

Re: Efficiency Question

Posted 14 September 2012 - 12:06 PM

That was directed at the OP...
Was This Post Helpful? 0
  • +
  • -

#8 Bealebe  Icon User is offline

  • New D.I.C Head

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

Re: Efficiency Question

Posted 14 September 2012 - 12:07 PM

View Postmodi123_1, on 14 September 2012 - 12:06 PM, said:

That was directed at the OP...



Gotcha, I'll be sure to do that from now on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1