Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Debugging Problem in Halvorson's Book

Debugging Problem in Halvorson's Book

Scheduled Pinned Locked Moved Visual Basic
helptutoriallearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tanstaafl28
    wrote on last edited by
    #1

    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...

    D S 2 Replies Last reply
    0
    • T tanstaafl28

      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...

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        T Offline
        T Offline
        tanstaafl28
        wrote on last edited by
        #3

        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...

        1 Reply Last reply
        0
        • T tanstaafl28

          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...

          S Offline
          S Offline
          Steven Campbell
          wrote on last edited by
          #4

          Assuming that Age is an integer, there is absolutely no difference. In programming, there is almost never one single right answer :)

          T 1 Reply Last reply
          0
          • S Steven Campbell

            Assuming that Age is an integer, there is absolutely no difference. In programming, there is almost never one single right answer :)

            T Offline
            T Offline
            tanstaafl28
            wrote on last edited by
            #5

            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...

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups