L.T.W. Posted January 31, 2008 Share Posted January 31, 2008 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 ) 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. .. Quote Link to comment Share on other sites More sharing options...
Kanthos Posted January 31, 2008 Share Posted January 31, 2008 Been a while since I've used VB and I don't have access to it (and don't really want to download the free version and install it at work), so I'm just going by the code. You have three checkboxes for specials; are you seeing the problem with all of them? Quote Link to comment Share on other sites More sharing options...
Kanthos Posted January 31, 2008 Share Posted January 31, 2008 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)) Quote Link to comment Share on other sites More sharing options...
L.T.W. Posted February 1, 2008 Author Share Posted February 1, 2008 THANK YOU SO VERY, VERY MUCH!!!!!!!!!!!! I dont know how I didnt see that before, I was probably to caught up with everything else. WOW, I'll be forever grateful to ya Quote Link to comment Share on other sites More sharing options...
Kanthos Posted February 1, 2008 Share Posted February 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
L.T.W. Posted February 2, 2008 Author Share Posted February 2, 2008 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) Quote Link to comment Share on other sites More sharing options...
phill Posted February 2, 2008 Share Posted February 2, 2008 because my professor is special he might not want me to do that IDK. I never understood why some teachers (and I have had ones like this) require you to practice bad programming. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.