{"id":293,"date":"2007-06-19T11:39:39","date_gmt":"2007-06-19T10:39:39","guid":{"rendered":"http:\/\/www.galhano.com\/blog\/?p=293"},"modified":"2017-01-12T11:55:16","modified_gmt":"2017-01-12T11:55:16","slug":"funcoes-matematicas-e-de-texto-em-vbnet","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=293","title":{"rendered":"Fun\u00e7\u00f5es Matem\u00e1ticas e de Texto em VB.Net"},"content":{"rendered":"<form id=\"ctl00\" action=\"http:\/\/msconline.maconstate.edu\/tutorials\/VBNET\/VBNET01\/vbnet01-06.aspx\" method=\"post\" name=\"ctl00\">\n<div class=\"divhead\">\u00c2 <span style=\"font-family: Verdana; font-size: small;\"><!--more--><\/span><\/div>\n<p class=\"head3\"><strong><span style=\"color: #f5f5f5; font-family: Verdana; font-size: small;\"><span style=\"background-color: #800000;\">\u00c2 Mathematical Functions\u00c2 <\/span><\/span><\/strong><\/p>\n<p><span style=\"font-family: Verdana; font-size: small;\">Popular mathematical functions are summarized in the following table. Note that certain functions do <em>not<\/em> require the <span class=\"code\">Math.<\/span> prefix.<\/span><\/p>\n<table id=\"table1\" border=\"0\" width=\"100%\" cellpadding=\"2\">\n<tbody>\n<tr style=\"background-color: #e6e6e6;\">\n<th style=\"background-color: #c0c0c0;\"><span style=\"font-family: Verdana; font-size: small;\">Function<\/span><\/th>\n<th style=\"background-color: #c0c0c0;\"><span style=\"font-family: Verdana; font-size: small;\">Use<\/span><\/th>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Abs()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the absolute value.<br \/>\n<span class=\"code\">Math.Abs(-10)<\/span> returns <span class=\"code\">10<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Ceiling()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns an integer that is greater than or equal to a number.<br \/>\n<span class=\"code\">Math.Ceiling(5.333)<\/span> returns <span class=\"code\">6<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Fix()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the integer portion of a number.<br \/>\n<span class=\"code\">Fix(5.3333)<\/span> returns <span class=\"code\">5<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Floor()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns an integer that is less than or equal to a number.<br \/>\n<span class=\"code\">Fix(5.3333)<\/span> returns <span class=\"code\">5<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Int()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the integer portion of a number.<br \/>\n<span class=\"code\">Int(5.3333)<\/span> returns <span class=\"code\">5<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Max()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the larger of two numbers.<br \/>\n<span class=\"code\">Math.Max(5,7)<\/span> returns <span class=\"code\">7<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Min()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the smaller of two numbers.<br \/>\n<span class=\"code\">Math.Min(5,7)<\/span> returns <span class=\"code\">5<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Pow()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns a number raised to a power.<br \/>\n<span class=\"code\">Math.Pow(12,2)<\/span> returns <span class=\"code\">144<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Rnd()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns a random number between 0 and 1. Used in conjunction with <span class=\"code\">Randomize<\/span>statement to initialize the random number generator.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Round()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Rounds a number to a specified number of decimal places. Rounds up on <span class=\"code\">.5<\/span>.<br \/>\n<span class=\"code\">Math.Round(1.1234567,5)<\/span> returns <span class=\"code\">1.12346<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Sign()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the sign of a number. Returns <span class=\"code\">-1<\/span> if negative and <span class=\"code\">1<\/span> if positive.<br \/>\n<span class=\"code\">Math.Sign(-5)<\/span> returns <span class=\"code\">-1<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Math.Sqrt()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the square root of a positive number.<br \/>\n<span class=\"code\">Math.Sqrt(144)<\/span> returns <span class=\"code\">12<\/span>.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"head3\">\u00c2<\/p>\n<p class=\"head3\"><span style=\"color: #f5f5f5; font-family: Verdana; font-size: small;\"><strong><span style=\"background-color: #800000;\">\u00c2 Random Numbers\u00c2 <\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: Verdana; font-size: small;\">The <span class=\"code\">Rnd()<\/span> function returns a random number between 0 and 1. More likely, the need is to generate a number within a particular range, between a given low and high<\/span><\/p>\n<p><span style=\"font-family: Verdana; font-size: small;\">\u00c2 number. This is accomplished with the following formula.<\/span><\/p>\n<table id=\"table2\" border=\"1\" width=\"100%\" cellspacing=\"1\" cellpadding=\"4\" bgcolor=\"#800000\">\n<tbody>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Math.floor((<em>high<\/em> &#8211; <em>low<\/em> + 1) * Rnd() + <em>low<\/em>) <\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Verdana; font-size: small;\">For instance, to generate a random number between 0 and 10 the formula becomes<\/span><\/p>\n<pre class=\"code\"><span style=\"font-family: Verdana;\">Math.floor((10 - 0 + 1) * Rnd() + 0)<\/span><\/pre>\n<p>\u00c2<\/p>\n<p>\u00c2<\/p>\n<p class=\"head2\"><span style=\"color: #f5f5f5; font-family: Verdana; font-size: small;\"><strong><span style=\"background-color: #800000;\">\u00c2 String Functions\u00c2 <\/span><\/strong><\/span><\/p>\n<p><span style=\"font-family: Verdana; font-size: small;\">Several built-in string functions perform string manipulations to augment simple concatenation with the <span class=\"code\">&#8220;&amp;&#8221;<\/span> operator. These functions are summarized in the following table.<\/span><\/p>\n<table id=\"table3\" border=\"0\" cellpadding=\"2\">\n<tbody>\n<tr style=\"background-color: #e6e6e6;\">\n<th style=\"background-color: #c0c0c0;\"><span style=\"font-family: Verdana; font-size: small;\">Function<\/span><\/th>\n<th style=\"background-color: #c0c0c0;\"><span style=\"font-family: Verdana; font-size: small;\">Use<\/span><\/th>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Asc()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the character code of the first character of a string.<br \/>\n<span class=\"code\">Asc(&#8220;A&#8221;)<\/span> returns <span class=\"code\">65<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Chr()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the display character of a character code.<br \/>\n<span class=\"code\">Chr(65)<\/span> returns <span class=\"code\">&#8220;A&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>GetChar()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the character at a specified position in a string, counting from 1.<br \/>\n<span class=\"code\">GetChar(&#8220;This is a string&#8221;, 7)<\/span> returns <span class=\"code\">&#8220;s&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>InStr()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the starting position in a string of a substring, counting from 1.<br \/>\n<span class=\"code\">InStr(&#8220;This is a string&#8221;, &#8220;string&#8221;)<\/span> returns <span class=\"code\">11<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>InStrRev()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the starting position in a string of a substring, searching from the end of the string.<br \/>\n<span class=\"code\">InStr(&#8220;This is a string&#8221;, &#8220;string&#8221;)<\/span> returns <span class=\"code\">11<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>LCase()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the lower-case conversion of a string.<br \/>\n<span class=\"code\">LCase(&#8220;THIS IS A STRING&#8221;)<\/span> returns <span class=\"code\">&#8220;this is a string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Left()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the left-most specified number of characters of a string.<br \/>\n<span class=\"code\">Left(&#8220;This is a string&#8221;, 4)<\/span> returns <span class=\"code\">&#8220;This&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Len()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the length of a string.<br \/>\n<span class=\"code\">Len(&#8220;This is a string&#8221;)<\/span> returns <span class=\"code\">16<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>LTrim()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Removes any leading spaces from a string.<br \/>\n<span class=\"code\">LTrim(&#8220;\u00c2 \u00c2 \u00c2 This is a string&#8221;)<\/span> returns <span class=\"code\">&#8220;This is a string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Mid()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns a substring from a string, specified as the starting position (counting from 1) and the number of characters.<br \/>\n<span class=\"code\">Mid(&#8220;This is a string&#8221;, 6, 4)<\/span> returns <span class=\"code\">&#8220;is a&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Replace()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Replaces all occurences of a substring in a string.<br \/>\n<span class=\"code\">Replace(&#8220;This is a string&#8221;, &#8221; s&#8221;, &#8221; longer s&#8221;)<\/span> returns <span class=\"code\">&#8220;This are a longer string&#8221;<\/span> (replaces an &#8220;s&#8221; preceded by a blank space).<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Right()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the right-most specified number of characters of a string.<br \/>\n<span class=\"code\">Right(&#8220;This is a string&#8221;, 6)<\/span> returns <span class=\"code\">&#8220;string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>RTrim()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Removes any trailing spaces from a string.<br \/>\n<span class=\"code\">RTrim(&#8220;This is a string\u00c2 \u00c2 \u00c2 &#8220;)<\/span> returns <span class=\"code\">&#8220;This is a string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Str()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Returns the string equivalent of a number.<br \/>\n<span class=\"code\">Str(100)<\/span> returns <span class=\"code\">&#8220;100&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Space()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Fills a string with a given number of spaces.<br \/>\n<span class=\"code\">&#8220;This&#8221; &amp; Space(5) &amp; &#8220;string&#8221;<\/span> returns <span class=\"code\">&#8220;This\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>StrComp()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Compares two strings. Return values are 0 (strings are equal), 1 (first string has the greater value), or -1 (second string has the greater value) based on sorting sequence.<br \/>\n<span class=\"code\">StrComp(&#8220;This is a string&#8221;, &#8220;This string&#8221;)<\/span> returns <span class=\"code\">-1<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>StrReverse()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Reverses the characters in a string.<br \/>\n<span class=\"code\">StrReverse(&#8220;This is a string&#8221;)<\/span> returns <span class=\"code\">&#8220;gnirts a si sihT&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Trim()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Removes any leading and trailing spaces from a string.<br \/>\n<span class=\"code\">Trim(&#8220;\u00c2 \u00c2 \u00c2 This is a string\u00c2 \u00c2 \u00c2 &#8220;)<\/span> returns <span class=\"code\">&#8220;This is a string&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\"><strong>UCase()<\/strong><\/span><\/td>\n<td bgcolor=\"#e1e1ff\"><span style=\"font-family: Verdana; font-size: small;\">Returns the upper-case conversion of a string.<br \/>\n<span class=\"code\">UCase(&#8220;This is a string&#8221;)<\/span> returns <span class=\"code\">&#8220;THIS IS A STRING&#8221;<\/span>.<\/span><\/td>\n<\/tr>\n<tr>\n<td class=\"code\" bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\"><strong>Val()<\/strong><\/span><\/td>\n<td bgcolor=\"#f5f5f5\"><span style=\"font-family: Verdana; font-size: small;\">Converts a numeric expression to a number.<br \/>\n<span class=\"code\">Val( (1 + 2 + 3)^2 )<\/span> returns <span class=\"code\">36<\/span>.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family: Verdana; font-size: small;\">The above summaries give you a basic idea of the uses of these arithmetic and string functions. There are occasions throughout these tutorials to see them in action and in combination as they are applied to various processing needs.\u00c2 \u00c2 \u00c2 <\/span><\/p>\n<p>\u00c2<\/p>\n<p><span style=\"font-family: Verdana; font-size: small;\"><em><strong>Fonte:<\/strong><\/em><a href=\"http:\/\/msconline.maconstate.edu\/tutorials\/VBNET\/VBNET01\/vbnet01-06.aspx\">http:\/\/msconline.maconstate.edu\/tutorials\/VBNET\/VBNET01\/vbnet01-06.aspx<\/a><\/span><\/p>\n<\/form>\n","protected":false},"excerpt":{"rendered":"<p>\u00c2<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,42],"tags":[],"class_list":["post-293","post","type-post","status-publish","format-standard","hentry","category-tutorials","category-utils","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293"}],"version-history":[{"count":1,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":2095,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions\/2095"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}