Jump to content

Any VB literates here>


L.T.W.
 Share

Recommended Posts

Im having problems with a program I'm making and since its too late at night to ask my professor I'll ask here.

Here is the whole thing if you have VB2005+ you can open it and check it out.

My Problem is (logical most likely) that when I hit the Special checkbox instead of subtracting the percentage from the price, its replacing it. You can see the problem if you run the file.

Everything else works (as far as I know :P)

PS: I know there are site dedicated to help people with VB programing, but they take 4ever to answer. And I also like you guys.

.. :P

Link to comment
Share on other sites

Actually, think I've found your problem. In all three of the chbNNNNNSpecial_CheckedChanged methods, you have a line like the following:

.decSinglePrice = Convert.ToDecimal(decDefaultSinglePrice * dblSpecial)

This is setting your price for a single (or CD or cassette) to be the default price multiplied by the special price, which is, I think, your discount. What you want is something like this:

.decSinglePrice = Convert.ToDecimal(decDefaultSinglePrice - (decDefaultSinglePrice * dblSpecial))

Link to comment
Share on other sites

No problem. Only took me about 3 minutes to read your code and see the problem and another two to post the answer.

Obviously, you don't care about this kind of thing for this particular assignment, but can I give you a suggestion to make your code more robust in the future?

You have a number of routines that do the same thing but work with different form elements. For example, you made that calculation error in three nearly-identical routines. A better way to code that would be to have your check box routines be very small: all they should do is get the appropriate data out of the text fields and call some other method that would actually do the calculation, something like function applyDiscount(ByRef originalPrice as Int, ByRef discountRate as Int). (Apologies if I have the syntax wrong here). The ByRef part is important because it allows you to change the original variables that you pass in, so that you can have the same routine operate on three pairs of variables without having to code those variables explicitly.

If your code had been written this way, you'd only have introduced your pricing error in one place. In a small program like this, it's not a big deal, but in a large program, you might fix the bug in one place but not in another, and be confused as to why it didn't work unless you exhaustively test the program.

Link to comment
Share on other sites

No problem. Only took me about 3 minutes to read your code and see the problem and another two to post the answer.

Obviously, you don't care about this kind of thing for this particular assignment, but can I give you a suggestion to make your code more robust in the future?

You have a number of routines that do the same thing but work with different form elements. For example, you made that calculation error in three nearly-identical routines. A better way to code that would be to have your check box routines be very small: all they should do is get the appropriate data out of the text fields and call some other method that would actually do the calculation, something like function applyDiscount(ByRef originalPrice as Int, ByRef discountRate as Int). (Apologies if I have the syntax wrong here). The ByRef part is important because it allows you to change the original variables that you pass in, so that you can have the same routine operate on three pairs of variables without having to code those variables explicitly.

If your code had been written this way, you'd only have introduced your pricing error in one place. In a small program like this, it's not a big deal, but in a large program, you might fix the bug in one place but not in another, and be confused as to why it didn't work unless you exhaustively test the program.

That sounds like its would work better.

I'll check it out after I turn the assignment, because my professor is special he might not want me to do that IDK.

But next class he will give us to do something similar but using inherited classes.

And fallowing the Presentation. Business and Data tiers. Which are new to me, but dont seem to hard to fallow. (I hope)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...