# Programming 12: Math Operations The class then typed in code for the “Add” button in which it calculated the sum of two numbers in the text fields but crashed when one of its input is numeric. This issue was addressed in the String Operations example in which the class learned how to check if the input in the text fields are numeric and how to combine two or more strings. These examples can be found on the school network drive under S:\Handout\Programming 11-12. Note: You must copy the folders onto your desktop or your storage device. You will not be able to save and run from the read-only network drive. Assignment: You will modify the Math Operations example that meets the following criteria

1. The results can be decimals. For example, if 12.1 and 23.4 are entered into the text fields, the result is 35.5.
2. The program adds, subtracts, multiplies and divides numbers. It then displays the result in a MsgBox.
3. The text in the MsgBox displays a sentence. For example, if 12 and 13 are entered, it displays “The sum is 25.” rather than just “25”. To do this, review how to join strings in the the String Operations example.
4. If one of the inputs in non-numeric (i.e. blank or text), then the MsgBox displays “Enter numbers only.”. To do this, review the IsNumeric function in the String Operations example.
5. The text in the MsgBox displays “Unable to divide.” if the second number is zero when dividing. To do this, the input has to be a number and then check if it is zero. There are two ways to check:
 ```If (num2 <> 0) Then      normal division Else      error message End If``` ```If (num2 = 0) Then      error message Else      normal division End If```
When complete, zip the entire folder in Projects and then upload the file onto the shared Google Drive folder. Evaluation: Total 10 marks
• Proper comments and well-labeled names (2 marks)
• Add, subtract, multiply and divide (4 marks)
• Includes decimal inputs and outputs.
• Exceptions (2 marks)
• Non-numeric
• Division by 0
• Visual Design (2 marks)
• Displays “The result is ___.” with a period.
• No spelling, grammar or punctuation errors in MsgBox.
• Visually nice and easy to use.
Tips:
1. Take time to edit the “Add” button properly so that it displays the result in a sentence and handles non-numeric inputs properly. After this is done, copy/paste and modify the other three arithmetic operations.
2. To display a number with a string in a message box, you need to type:
`MsgBox("The sum is " + sum.ToString())`
3. To check if your text fields are numeric, you need to type:
```' Create variables Dim num1 As Decimal ... If (IsNumeric(Input1.Text) and IsNumeric(Input2.Text)) Then      ' Store into variables      num1 = Input1.Text      ...      ' Calculate and display result Else      ' Display error message End If```
4. Handle the “division by zero” exception last. Hint: Both inputs must be numbers before you can check if the second input is zero.
]]>
{"ft_lang_label":"__label__en","ft_lang_prob":0.7712659,"math_prob":0.87388253,"size":2721,"snap":"2021-43-2021-49","text_gpt3_token_len":632,"char_repetition_ratio":0.11409643,"word_repetition_ratio":0.020661157,"special_character_ratio":0.24696803,"punctuation_ratio":0.122262776,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99293965,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-12-03T12:49:28Z\",\"WARC-Record-ID\":\"<urn:uuid:c3b9ff8c-2b8d-4197-bea8-765316c98ad6>\",\"Content-Length\":\"39753\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9320f95a-ae9d-4ddb-a1eb-0842590c484d>\",\"WARC-Concurrent-To\":\"<urn:uuid:08ca8dba-5933-4760-be1d-c48fc7985772>\",\"WARC-IP-Address\":\"69.90.162.180\",\"WARC-Target-URI\":\"https://mrkam.ca/posts/programming-12-math-operations/\",\"WARC-Payload-Digest\":\"sha1:VG43QVKHWOBKM5OPPBYV7Q33R5YRZGNC\",\"WARC-Block-Digest\":\"sha1:RYHVM5GUAESVA2LJS4HCY4ULZX3DFXI5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-49/CC-MAIN-2021-49_segments_1637964362879.45_warc_CC-MAIN-20211203121459-20211203151459-00053.warc.gz\"}"}