Example: Writing a Four-Function Calculator

When you wrote the tape calculator example in Chapter 3, you probably wondered why it didn’t also multiply and divide. Perhaps, if you like to tinker, you tried adding those functions. Recall, though, that the btnAdd_Click and btnSubtract_Click subroutines contained a lot of duplicate code. The instructions even told you to cut and paste it. This example explains how to implement all four functions without duplicating any code. Follow this procedure:

  1. In Visual Studio, create a new Windows Forms project named Calc3.

  2. Either quit Visual Studio or make sure none of the files in the Calc3 project are open. (That is, make sure the main document window is empty.)

  3. In Windows Explorer, copy the Form1.vb file ...

Get Faster Smarter Beginning Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.