View Single Post
  #9 (permalink)  
Old April 25th, 2016, 05:51 PM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Good questions.

Quote:
Just where did we tell the program that "last_letter" is the previous numeric value in the string?
The code first sets last_letter to 0, which is smaller than any value that a Roman numeral letter can have. That means when we look at the first letter on the right, last_letter will always be smaller so we add.

After the tests, we set last_letter = new_letter so we remember what the most recent letter was during the next trip through the loop.

Quote:
Second, I think you are using "Return" function instead of my "GoTo." To which point in the code exactly does it return?
The way modern event-driven programs work is that they display a user interface and then just sit there waiting for the user to do something. When you click the button, it's Click event handler springs into action so do something, in this example performing the Roman-to-Arabic calculation.

When the event handler exits, control goes back to the main event processing code, which is handled automatically for you, and the program sits around waiting for you to do something again such as clicking the button.

The Return statement tells the event handler to just exit early. Control returns to the event processing code as if the event handler had ended normally.

(PS - This sort of thing isn't hard, but it does take practice.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
Maximilian (April 26th, 2016)