2. Start fresh Start VS 2005 and Create a new project: Calculator_IT1C_xx Choose appropriate directory and remember its path Exit VS 2005 Unzip start_cal.zip: Form1.vb and Form1.Designer.vb Use File explorer to replace the two newly created project files in Calculator_IT1C_xx
3. ButtonSqrt_Click Double click on the button for Sqrt to generate the ButtonSqrt_Click subroutine Copy the codes from ButtonEqual_Click Modify the following line to use Math.Sqrt total = total + x total = Math.Sqrt(x)
4. ButtonPercent_Click Double click on the button for % to generate the ButtonPercent_Click subroutine Copy the codes from ButtonEqual_Click Modify the following line to use Math.Sqrt total = total + x total = x / 100
5. Dot Private Sub ButtonDot_Click ‘ Copy the codes from Button0 ‘ Replace “0” with “.” Dim existingString As String = TextBox1.Text If existingString <> "" Then TextBox1.Text = existingString & "0" End If End Sub “.”
7. Dot Private Sub ButtonDot_Click ‘ Add else condition ‘ to add “0.” Dim existingString As String = TextBox1.Text If existingString <> "" Then TextBox1.Text = existingString & “.” End If End Sub Else TextBox1.Text = existingString & “0.” End If End Sub
8. Testing 1.5 OK 0.5 OK 1.5.5. => should not allow – How?
9. How to stop “1.5.5.”? We need to use a global variable to track if “.” has been set Then add additional codes in ButtonDot to check this variable
11. Dot Private Sub ButtonDot_Click ‘ Add Condition to check for isDotted Dim existingString As String = TextBox1.Text If existingString <> "" Then TextBox1.Text = existingString & “.” Else TextBox1.Text = existingString & “0.” End If End Sub If isDotted = False Then isDotted= True ‘ Set isDotted to True End If End Sub
12. Testing 1.5 OK 0.5 OK 1.5.5. OK 1.5 Clear 1.5 => NG - How?
13. Dot Private Sub ButtonClear_Click : : ‘ Reset isDotted to False isDotted = False End Sub
14. Testing 1.5 OK 0.5 OK 1.5.5. OK 1.5 Clear 1.5 OK 1.5 + 1.5 => NG – How?
15. Dot Private Sub ButtonPlus_Click : : ‘ Reset isDotted to False isDotted = False End Sub
16. Testing 1.5 OK 0.5 OK 1.5.5. OK 1.5 Clear 1.5 OK 1.5 + 1.5 OK Anymore cases?
17. Minus, Multiply and Divide Before we proceed to add the processing for Minus, Multiply and Divide, we need to modify the current processing for Plus and Equal
18. Modify Plus and Equal Private Sub ButtonPlus_Click : : total = total + x : End Sub total = x ‘ Now, Plus can only be ‘ pressed once.
19. Modify Plus and Equal Global variable: Public Class Form1 Dim whatFunction As String = “None”
20. Modify Plus and Equal Private Sub ButtonPlus_Click : : whatFunction = “Plus” End Sub
21. Modify Plus and Equal Private Sub ButtonEqual_Click : : total = total + x : End Sub Select Case whatFunction Case “Plus” total = total + x End Select Case “Minus”
22. Add Minus, Multiply and Divide Complete the processing for minus, multiply and divide. Take care of divide by zero error with if then else statement Do testingand debugging to take care of other errors