SlideShare une entreprise Scribd logo
1  sur  22
Start Fresh Download from 	TPITVB.blogspot.com 2 1
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
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)
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
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 “.”
Testing 1.5  OK 0.5  NG  => How?
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
Testing 1.5  OK 0.5  OK 1.5.5.  => should not allow – How?
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
Dot Global variable: Public Class Form1 Dim isDotted As Boolean = False
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
Testing 1.5  OK 0.5  OK 1.5.5. OK 1.5  Clear  1.5  => NG - How?
Dot Private Sub ButtonClear_Click 		: 		: 	‘ Reset isDotted to False isDotted = False End Sub
Testing 1.5  OK 0.5  OK 1.5.5. OK 1.5  Clear  1.5  OK 1.5 + 1.5 => NG – How?
Dot Private Sub ButtonPlus_Click 			: 			: 	‘ Reset isDotted to False isDotted = False End Sub
Testing 1.5  OK 0.5  OK 1.5.5. OK 1.5  Clear  1.5  OK 1.5 + 1.5 OK Anymore cases?
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
Modify Plus and Equal Private Sub ButtonPlus_Click 			: 			: 	total  =   total  +  x 			: End  Sub total  =  x		‘  Now, Plus can only be 				‘  pressed once.
Modify Plus and Equal Global variable: Public Class Form1 	Dim  whatFunction  As  String  =  “None”
Modify Plus and Equal Private Sub ButtonPlus_Click 			: 			: whatFunction = “Plus” End  Sub
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”
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

Contenu connexe

Tendances

Providing sl no in Gridview in Dot Net
Providing sl no in Gridview in Dot NetProviding sl no in Gridview in Dot Net
Providing sl no in Gridview in Dot NetDharma Raju
 
Web services in asp.net
Web services in asp.netWeb services in asp.net
Web services in asp.netDharma Raju
 
Keyboard shortcut - Phím tắt hệ điều hành windows 10
Keyboard shortcut - Phím tắt hệ điều hành windows 10Keyboard shortcut - Phím tắt hệ điều hành windows 10
Keyboard shortcut - Phím tắt hệ điều hành windows 10Sơn Đặng Thái
 
How to add sql server table into dot net web page (Gridview)
How to add sql server table into dot net web page (Gridview)How to add sql server table into dot net web page (Gridview)
How to add sql server table into dot net web page (Gridview)Dharma Raju
 
How to add sorting and pagers to grid view
How to add sorting and pagers to grid viewHow to add sorting and pagers to grid view
How to add sorting and pagers to grid viewDharma Raju
 

Tendances (6)

Providing sl no in Gridview in Dot Net
Providing sl no in Gridview in Dot NetProviding sl no in Gridview in Dot Net
Providing sl no in Gridview in Dot Net
 
Web services in asp.net
Web services in asp.netWeb services in asp.net
Web services in asp.net
 
Keyboard shortcut - Phím tắt hệ điều hành windows 10
Keyboard shortcut - Phím tắt hệ điều hành windows 10Keyboard shortcut - Phím tắt hệ điều hành windows 10
Keyboard shortcut - Phím tắt hệ điều hành windows 10
 
How to add sql server table into dot net web page (Gridview)
How to add sql server table into dot net web page (Gridview)How to add sql server table into dot net web page (Gridview)
How to add sql server table into dot net web page (Gridview)
 
How to add sorting and pagers to grid view
How to add sorting and pagers to grid viewHow to add sorting and pagers to grid view
How to add sorting and pagers to grid view
 
Bd1 erdenejargal b 2
Bd1 erdenejargal b 2Bd1 erdenejargal b 2
Bd1 erdenejargal b 2
 

Similaire à How to add basic math functions like addition, subtraction, multiplication and division to a calculator program

Calculator 4
Calculator 4Calculator 4
Calculator 4livecode
 
Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Mohammad Shaker
 
Cognos TM1 Assignments
Cognos TM1 Assignments Cognos TM1 Assignments
Cognos TM1 Assignments rameshkp054
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedshyaminfo04
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedash52393
 
Ankit Phadia Hacking tools (1)
Ankit Phadia Hacking tools (1)Ankit Phadia Hacking tools (1)
Ankit Phadia Hacking tools (1)Chandra Pr. Singh
 
Numerical modeling of concrete in Abaqus
Numerical modeling of concrete in Abaqus Numerical modeling of concrete in Abaqus
Numerical modeling of concrete in Abaqus Harish Kant Soni
 
Calculator 5
Calculator 5Calculator 5
Calculator 5livecode
 
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesCookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesEmiel Paasschens
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6Vince Vo
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 

Similaire à How to add basic math functions like addition, subtraction, multiplication and division to a calculator program (20)

Calculator 4
Calculator 4Calculator 4
Calculator 4
 
Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2Delphi L08 Controls at Runtime P2
Delphi L08 Controls at Runtime P2
 
Cognos TM1 Assignments
Cognos TM1 Assignments Cognos TM1 Assignments
Cognos TM1 Assignments
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
 
Devry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting startedDevry cis 170 c i lab 1 of 7 getting started
Devry cis 170 c i lab 1 of 7 getting started
 
Ankit Phadia Hacking tools (1)
Ankit Phadia Hacking tools (1)Ankit Phadia Hacking tools (1)
Ankit Phadia Hacking tools (1)
 
Steps how to do cmd
Steps how to do cmdSteps how to do cmd
Steps how to do cmd
 
Numerical modeling of concrete in Abaqus
Numerical modeling of concrete in Abaqus Numerical modeling of concrete in Abaqus
Numerical modeling of concrete in Abaqus
 
Calculator 5
Calculator 5Calculator 5
Calculator 5
 
TDD, BDD and mocks
TDD, BDD and mocksTDD, BDD and mocks
TDD, BDD and mocks
 
Tutorials.pdf
Tutorials.pdfTutorials.pdf
Tutorials.pdf
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Web Server Controls CS Set
Web Server Controls CS Set Web Server Controls CS Set
Web Server Controls CS Set
 
Cpp Homework Help
Cpp Homework Help Cpp Homework Help
Cpp Homework Help
 
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business RulesCookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Ankit Phadia Hacking tools
Ankit Phadia Hacking toolsAnkit Phadia Hacking tools
Ankit Phadia Hacking tools
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Gui builder
Gui builderGui builder
Gui builder
 

Plus de Hock Leng PUAH

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image SlideshowHock Leng PUAH
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introductionHock Leng PUAH
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingHock Leng PUAH
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash fileHock Leng PUAH
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthHock Leng PUAH
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime exampleHock Leng PUAH
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) functionHock Leng PUAH
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteHock Leng PUAH
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleHock Leng PUAH
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common ErrorsHock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectHock Leng PUAH
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelHock Leng PUAH
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises GuideHock Leng PUAH
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connectionHock Leng PUAH
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryHock Leng PUAH
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guideHock Leng PUAH
 

Plus de Hock Leng PUAH (20)

ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 
Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birthPHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
 
PHP built-in function mktime example
PHP built-in function mktime examplePHP built-in function mktime example
PHP built-in function mktime example
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 

Dernier

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 

Dernier (20)

Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

How to add basic math functions like addition, subtraction, multiplication and division to a calculator program

  • 1. Start Fresh Download from TPITVB.blogspot.com 2 1
  • 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 “.”
  • 6. Testing 1.5 OK 0.5 NG => How?
  • 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
  • 10. Dot Global variable: Public Class Form1 Dim isDotted As Boolean = False
  • 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