Debugging Problem in Halvorson's Book
-
Hiya, I'm in the middle of Mike Halvorson's Visual Basic Step By Step and there was a simple debugging problem where the ap prompts the user for their age and based upon this age, identifies them as either a teenager or not a teenager. The ap has a probem because one of the lines includes: If Age > 13 and Age < 20 Then Textbox2.Text = "Your'e a teenager." This creates a logic error in the fact that 13 is not included in the range of acceptable numbers. I simply made it > 12, but the book took the >=13 approach. Only wanted to know if there was any reason why my solution wouldn't be just as viable as the book's. Thanks. ;P Still coaxing software out of the can after all these years...
-
Hiya, I'm in the middle of Mike Halvorson's Visual Basic Step By Step and there was a simple debugging problem where the ap prompts the user for their age and based upon this age, identifies them as either a teenager or not a teenager. The ap has a probem because one of the lines includes: If Age > 13 and Age < 20 Then Textbox2.Text = "Your'e a teenager." This creates a logic error in the fact that 13 is not included in the range of acceptable numbers. I simply made it > 12, but the book took the >=13 approach. Only wanted to know if there was any reason why my solution wouldn't be just as viable as the book's. Thanks. ;P Still coaxing software out of the can after all these years...
So long as your using Integers only, no there is no difference. But, what if Age was 12.5? Your code would set return true, while the authors code would not. Never trust user input. Validate, Validate, Validate, Validate, and check it again before you use it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
So long as your using Integers only, no there is no difference. But, what if Age was 12.5? Your code would set return true, while the authors code would not. Never trust user input. Validate, Validate, Validate, Validate, and check it again before you use it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
I understand. When I saw the problem, I instinctively thought of 12 and couldn't think of an exception where this would not work, but you are correct, if someone used a decimal, the logic error would recur.:-D Still coaxing software out of the can after all these years...
-
Hiya, I'm in the middle of Mike Halvorson's Visual Basic Step By Step and there was a simple debugging problem where the ap prompts the user for their age and based upon this age, identifies them as either a teenager or not a teenager. The ap has a probem because one of the lines includes: If Age > 13 and Age < 20 Then Textbox2.Text = "Your'e a teenager." This creates a logic error in the fact that 13 is not included in the range of acceptable numbers. I simply made it > 12, but the book took the >=13 approach. Only wanted to know if there was any reason why my solution wouldn't be just as viable as the book's. Thanks. ;P Still coaxing software out of the can after all these years...
Assuming that Age is an integer, there is absolutely no difference. In programming, there is almost never one single right answer :)
-
Assuming that Age is an integer, there is absolutely no difference. In programming, there is almost never one single right answer :)
David pointed out the integer issue. I hadn't thought of that. I'll have to check the code and see if it would allow decimal increments, if it would, then perhaps the >=13 would be a better solution for eliminating a potential logic error. I think I'll suggest that it be pointed out in future editions. It can make a big difference. Still coaxing software out of the can after all these years...