{"id":2289,"date":"2013-02-08T15:34:33","date_gmt":"2013-02-08T07:34:33","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T17:48:32","modified_gmt":"2018-06-24T09:48:32","slug":"visual-basic-2012-lesson-7-mathematical-operations","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/","title":{"rendered":"Visual Basic 2012 Lesson 7- Mathematical Operations"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-6-managing-data\/\">[Lesson 6] <\/a>&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/\">[Lesson 8]<\/a><\/strong><\/h4>\n<p>In Visual Basic 2012, we can write code to instruct the computer to perform mathematical operations. To write code for mathematical operations, we need to use arithmetic operators. Visual Basic 2012 arithmetic operators are very similar to the normal arithmetic operators, only with little variations. The plus and minus operators are the same while the multiplication operator uses the * symbol and the division operator uses the \/ symbol. The list of Visual Basic 2012 arithmetic operators is shown in Table 7.1.<\/p>\n<h4>Table 7.1<\/h4>\n<div style=\"overflow-x:auto;\">\n<table>\n<tbody>\n<tr>\n<th style=\"text-align:center; width:20%\">Operator<\/th>\n<th>Mathematical Function<\/th>\n<th>Example<\/th>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>Addition<\/td>\n<td>\u00a01+2=3<\/td>\n<\/tr>\n<tr>\n<td>&#8211;<\/td>\n<td>\u00a0Subtraction<\/td>\n<td>\u00a010-4=6<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>\u00a0Exponential<\/td>\n<td>\u00a03^2=9<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>\u00a0Multiplication<\/td>\n<td>\u00a05*6=30<\/td>\n<\/tr>\n<tr>\n<td>\/<\/td>\n<td>\u00a0Division<\/td>\n<td>\u00a021\/7=3<\/td>\n<\/tr>\n<tr>\n<td>Mod<\/td>\n<td>\u00a0Modulus(returns the remainder of an integer division)<\/td>\n<td>\u00a015 Mod 4=3<\/td>\n<\/tr>\n<tr>\n<td>\\<\/td>\n<td>\u00a0Integer Division(discards the decimal places)<\/td>\n<td>\u00a019\/4=4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 7.1<\/h4>\n<p>In this program, insert two Textboxes, four labels, and a button. Click the button and enter the code as shown below. \u00a0When you run the program, it will perform the four basic arithmetic operations and displays the results on the four labels.<\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\nDim num1, num2, difference, product, quotient As Single\r\nnum1 = TextBox1.Text\r\nnum2 = TextBox2.Text\r\n\r\n sum=num1+num2\r\n difference=num1-num2\r\n product = num1 * num2\r\n quotient=num1\/num2\r\n Label1.Text=sum\r\n Label2.Text=difference\r\n Label3.Text = product\r\n Label4.Text = quotient\r\n\r\nEnd Sub\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 7.2<\/h4>\n<p>The program can use Pythagoras Theorem to calculate the length of hypotenuse c given the length of the adjacent side a and the opposite side b. In case you have forgotten the formula for the Pythagoras Theorem, it is written as<br \/>\nc^2=a^2+b^2<\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\nDim a, b, c As Single\r\n a = TextBox1.Text\r\n b = TextBox2.Text\r\n c=(a^2+b^2)^(1\/2)\r\n Label3.Text=c\r\nEnd Sub\r\n<\/pre>\n<h4>Example 7.3: BMI Calculator<\/h4>\n<p>A lot of people are obese now and it could affect their health seriously. Obesity has proven by the medical experts to be one of the main factors that bring many adverse medical problems, including the cardiovascular disease. If your BMI is more than 30, you are considered obese. You can refer to the following range of BMI values for your weight status.<\/p>\n<p>Underweight = &lt;18.5<br \/>\nNormal weight = 18.5-24.9<br \/>\nOverweight = 25-29.9<br \/>\nObesity = BMI of 30 or greater<\/p>\n<p><span style=\"font-size: 16px;\">To calculate your BMI, you can create a VB BMI calculator. The BMI calculator can calculate the body mass index or BMI of a person based on the body weight in kilogram and the body height in meter. BMI can be calculated using the formula weight\/( height )^2, where weight is measured in kg and height in meter. If you only know your weight and height in lb and feet, then you need to convert them to the metric system (you could indeed write a VB program for the conversion).<\/span><\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArsgs) Handles Button1.Click\r\nDim height, weight, bmi As Single\r\n height = TextBox1.Text\r\n weight = TextBox2.Text\r\n bmi = (weight) \/ (height ^ 2)\r\nLabel4.Text = bmi\r\nEnd Sub\r\n<\/pre>\n<p>The output is shown in the figure below. In this example, your height is 1.80m( about 5 foot 11), your weight is 75 kg( about 168Ib), and your BMI is about 23.14815. The reading suggests that you are healthy. (Note; 1 foot=0.3048, 1 lb=.45359237 kilogram)<\/p>\n<p><center><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif\" alt=\"Visual Basic 2012 BMI Calculator\" width=\"300\" height=\"300\" \/><\/center><br \/>\nFrom the above examples, you can see that writing code that involve arithmetic operations is relatively easy. Here are more arithmetic projects you can try to program:<\/p>\n<p>Area of a triangle<br \/>\nArea of a rectangle<br \/>\nArea of a circle<br \/>\nVolume of a cylinder<br \/>\nVolume of a cone<br \/>\nVolume of a sphere<br \/>\nCompound interest<br \/>\nFuture value<br \/>\nMean<br \/>\nVariance<br \/>\nSum of angles in polygons<br \/>\nConversion of lb to kg<br \/>\nConversion of Fahrenheit to Celsius<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"6598395509\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-6-managing-data\/\">[Lesson 6] <\/a>&gt;&gt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-8-string-manipulation\/\">[Lesson 8]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 6] &gt;&gt; [CONTENTS] &gt;&gt; [Lesson 8] In Visual Basic 2012, we can write code to instruct the computer to perform mathematical operations. To write code for mathematical operations, we need to use arithmetic operators. Visual Basic 2012 arithmetic operators are very similar to the normal arithmetic operators, only with little variations. The plus and &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2012 Lesson 7- Mathematical Operations<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2289","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-24T09:48:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html\",\"name\":\"Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif\",\"datePublished\":\"2013-02-08T07:34:33+00:00\",\"dateModified\":\"2018-06-24T09:48:32+00:00\",\"description\":\"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2012 Lesson 7- Mathematical Operations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012","og_url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2018-06-24T09:48:32+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-7-mathematical-operations\/","url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html","name":"Visual Basic 2012 Lesson 7- Mathematical Operations - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif","datePublished":"2013-02-08T07:34:33+00:00","dateModified":"2018-06-24T09:48:32+00:00","description":"This visual basic 2012 shows how to perform Mathematical Operations in Visual Basic 2012","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#primaryimage","url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif","contentUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_7.1.gif"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson7.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2012 Lesson 7- Mathematical Operations"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=2289"}],"version-history":[{"count":38,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2289\/revisions"}],"predecessor-version":[{"id":13098,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2289\/revisions\/13098"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=2289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=2289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}