Start Fresh<br />Download from<br />	TPITVB.blogspot.com<br />2<br />1<br />
Start fresh<br />Start VS 2005 and Create a new project: Calculator_IT1C_xx<br />Choose appropriate directory and remember...
ButtonSqrt_Click<br />Double click on the button for Sqrt to generate the ButtonSqrt_Click subroutine<br />Copy the codes ...
ButtonPercent_Click<br />Double click on the button for % to generate the ButtonPercent_Click subroutine<br />Copy the cod...
Dot<br />Private Sub ButtonDot_Click<br />‘ Copy the codes from Button0<br />‘ Replace “0”  with “.”<br /> 	Dim existingSt...
Testing<br />1.5  OK<br />0.5  NG  =&gt; How?<br />
Dot<br />Private Sub ButtonDot_Click<br />‘ Add else condition<br />‘ to add “0.”<br />   Dim existingString As String = T...
Testing<br />1.5  OK<br />0.5  OK<br />1.5.5.  =&gt; should not allow – How?<br />
How to stop “1.5.5.”?<br />We need to use a global variable to track if “.” has been set <br />Then add additional codes i...
Dot<br />Global variable:<br />Public Class Form1<br />Dim isDotted As Boolean = False<br />
Dot<br />Private Sub ButtonDot_Click<br />‘ Add Condition to check for isDotted<br />Dim existingString As String = TextBo...
Testing<br />1.5  OK<br />0.5  OK<br />1.5.5. OK<br />1.5  Clear  1.5  =&gt; NG - How?<br />
Dot<br />Private Sub ButtonClear_Click<br />		:<br />		:<br />	‘ Reset isDotted to False<br />isDotted = False<br />End Su...
Testing<br />1.5  OK<br />0.5  OK<br />1.5.5. OK<br />1.5  Clear  1.5  OK<br />1.5 + 1.5 =&gt; NG – How?<br />
Dot<br />Private Sub ButtonPlus_Click<br />			:<br />			:<br />	‘ Reset isDotted to False<br />isDotted = False<br />End S...
Testing<br />1.5  OK<br />0.5  OK<br />1.5.5. OK<br />1.5  Clear  1.5  OK<br />1.5 + 1.5 OK<br />Anymore cases?<br />
Minus, Multiply and Divide<br />Before we proceed to add the processing for Minus, Multiply and Divide,<br />we need to mo...
Modify Plus and Equal<br />Private Sub ButtonPlus_Click<br />			:<br />			:<br />	total  =   total  +  x<br />			:<br />En...
Modify Plus and Equal<br />Global variable:<br />Public Class Form1<br />	Dim  whatFunction  As  String  =  “None”<br />
Modify Plus and Equal<br />Private Sub ButtonPlus_Click<br />			:<br />			:<br />whatFunction = “Plus”<br />End  Sub<br />
Modify Plus and Equal<br />Private Sub ButtonEqual_Click<br />			:<br />			:<br />	total = total + x<br />			:<br />End  S...
Add Minus, Multiply and Divide<br />Complete the processing for minus, multiply and divide.<br />Take care of divide by ze...
Upcoming SlideShare
Loading in …5
×

Calculator Processing

1,693 views

Published on

Logic for the calculator development.

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,693
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Calculator Processing

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

×