{"id":1095,"date":"2012-04-06T16:42:53","date_gmt":"2012-04-06T08:42:53","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2017-11-06T18:35:58","modified_gmt":"2017-11-06T10:35:58","slug":"visual-basic-2010-lesson-14","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-14\/","title":{"rendered":"Visual Basic 2010 Lesson 14- The Math Functions"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-13\/\">[Lesson 13]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-15\/\"> [Lesson 15]<\/a><\/strong><\/h4>\n<h2>What are Math Functions<\/h2>\n<p>Math functions in VB programming are functions that process one or more numbers and return a value. They are no different functions in mathematics. Though we can create customized math functions, \u00a0we can save time by using a score of built-in math functions in Visual Basic 2010.<\/p>\n<h3>14.1 The Abs function<\/h3>\n<p>The Abs function returns the absolute value of a given number.The syntax is<\/p>\n<pre style=\"font-size: 110%; width: 50%;\">Math. Abs (number)\r\n<\/pre>\n<p>* The Math keyword here indicates that the Abs function belongs to the Math class. However, not all math functions belong to the Math class.<\/p>\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=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>14.2 The Exp function<\/h3>\n<p>The Exp of a number x is the exponential value of x, i.e. e<sup>x<\/sup>.<\/p>\n<p>The syntax is:<\/p>\n<pre style=\"font-size: 110%; width: 50%;\"> Math.Exp (number)\r\n<\/pre>\n<p>For example,<\/p>\n<pre style=\"font-size: 110%; width: 50%;\">Exp(1)=e=2.71828182<\/pre>\n<h4>Example 14.1<\/h4>\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 As Single\r\n num1 = TextBox1.Text\r\n num2 = Math.Exp(num1)\r\n Label1.Text = num2\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=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>14.3 The Fix Function<\/h3>\n<p>The Fix function truncates the decimal part of a positive number and returns the largest integer smaller than the number. However, when the number is negative, it will return the smallest integer larger than the number. For example, Fix(9.2)=9 but Fix(-9.4)=-9<\/p>\n<h4>Example 14.2<\/h4>\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 As Single\r\n num1 = TextBox1.Text\r\n num2 = Fix(num1)\r\n Label1.Text = num2\r\nEnd Sub\r\n<\/pre>\n<h3>14.4 The Int Function<\/h3>\n<p>The Int is a function that converts a number into an integer by truncating its decimal part and the resulting integer is the largest integer that is smaller than the number. For example<\/p>\n<pre style=\"font-size: 110%;\">Int(2.4)=2, Int(6.9)=6 , Int(-5.7)=-6, Int(-99.8)=-100\r\n<\/pre>\n<h3>14.5 The Log Function<\/h3>\n<p>The Log function is the function that returns the natural logarithm of a number. For example, Log(10)=2.302585<\/p>\n<h4>Example 14.3<\/h4>\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 As Single\r\n num1 = TextBox1.Text\r\n num2 = Math.Log(num1)\r\n Label1.Text = num2\r\nEnd Sub\r\n<\/pre>\n<p>* The logarithm of num1 will be displayed on label1<\/p>\n<h3>14.6 The Rnd( ) Function<\/h3>\n<p>The Rnd function returns a random value between 0 and 1. Random numbers often need to be converted into integers in programming. For example, if we wish to obtain a random output of 6 integers ranging from 1 to 6, which makes the program behaves like a virtual dice, we need to convert the random numbers to integers using the formula Int(Rnd*6)+1.<\/p>\n<h4>Example 14.4<\/h4>\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 num as integer\r\n Num=Int(Rnd()*6)+1\r\n Label1.Text=Num\r\nEnd Sub\r\n<\/pre>\n<p>In this example, Int(Rnd*6) will generate a random integer between 0 and 5 because the function Int truncates the decimal part of the random number and returns an integer. After adding 1, you will get a random number between 1 and 6 every time you click the command button. For example, let say the random number generated is 0.98, after multiplying it by 6, it becomes 5.88, and using the integer function Int(5.88) will convert the number to 5, and after adding 1 you will get 6.<\/p>\n<h3>14.7 The Round Function<\/h3>\n<p>The Round function rounds up a number to a certain number of decimal places. The syntax is Round (n, m) which means to round a number n to m decimal places. For example,<\/p>\n<pre style=\"font-size: 110%; width: 80%;\">Math.Round (7.2567, 2) =7.26<\/pre>\n<h4>Example 14.5<\/h4>\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 As Single\r\n num1 = TextBox1.Text\r\n num2 = Math.Round(num1, 2)\r\n Label1.Text = num2\r\nEnd Sub\r\n<\/pre>\n<p>* The Math keyword indicates that the Round function belongs to the Math class.<br \/>\n<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=\"8075128701\"><\/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-2010-lesson-13\/\">[Lesson 13]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-15\/\"> [Lesson 15]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 13] &lt;&lt;\u00a0[CONTENTS] &gt;&gt; [Lesson 15] What are Math Functions Math functions in VB programming are functions that process one or more numbers and return a value. They are no different functions in mathematics. Though we can create customized math functions, \u00a0we can save time by using a score of built-in math functions in Visual &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-14\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2010 Lesson 14- The Math Functions<\/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-1095","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 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010\" \/>\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\/vb2010\/vb2010_lesson14.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.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=\"2017-11-06T10:35:58+00:00\" \/>\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-2010-lesson-14\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html\",\"name\":\"Visual Basic 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"datePublished\":\"2012-04-06T08:42:53+00:00\",\"dateModified\":\"2017-11-06T10:35:58+00:00\",\"description\":\"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2010 Lesson 14- The Math Functions\"}]},{\"@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 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010","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\/vb2010\/vb2010_lesson14.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010","og_url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.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":"2017-11-06T10:35:58+00:00","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-2010-lesson-14\/","url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html","name":"Visual Basic 2010 Lesson 14- The Math Functions - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"datePublished":"2012-04-06T08:42:53+00:00","dateModified":"2017-11-06T10:35:58+00:00","description":"This Visual Basic 2010 lesson describes the usage of math functions in Visual Basic 2010","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson14.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2010 Lesson 14- The Math Functions"}]},{"@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\/1095","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=1095"}],"version-history":[{"count":45,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1095\/revisions"}],"predecessor-version":[{"id":12488,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1095\/revisions\/12488"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}