{"id":1086,"date":"2012-04-06T16:40:52","date_gmt":"2012-04-06T08:40:52","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T19:04:00","modified_gmt":"2018-06-24T11:04:00","slug":"visual-basic-2010-lesson-10","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-10\/","title":{"rendered":"Visual Basic 2010 Lesson 10- Using Select Case"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-9\/\">[Lesson 9]<\/a> <\/strong>&lt;&lt; <strong> <a href=\"..\/..\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-11\/\">[Lesson 11]<\/a> <\/strong><\/h4>\n<p>In the previous lesson, we have learned the If&#8230;Then&#8230;Else control structure. In this lesson, you will learn another way to control the program flow in Visual Basic 2010, that is, the Select Case control structure. Select Case control structure is slightly different from the If&#8230;.Else&#8230;Then control structure. The difference is that the Select Case control structure typically only make a decision on one expression. On the other hand, the If &#8230;Then&#8230;Else statement control structure may evaluate only one expression, \u00a0or it may also compute entirely different dimensions. Select Case is preferred when there exist multiple conditions.<\/p>\n<h3>10.1 The Select Case&#8230;End Select Structure<\/h3>\n<p>The syntax of the Select Case control structure is as follows:<\/p>\n<pre style=\"font-size: 110%; width: 80%;\">Select Case test expression\r\nCase expression list 1\r\n Block of statements\r\nCase expression list 2\r\n Block of  Statements\r\n.\r\n.\r\nCase Else\r\n Block of  Statements\r\nEnd Select<\/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><br \/>\nThe usage of Select Case is shown in the following examples<\/p>\n<h4>Example 10.1<\/h4>\n<pre style=\"font-size: 110%; width: 70%;\">' Examination Grades\r\nDim grade As String\r\nPrivate Sub Compute_Click( )\r\n grade=txtgrade.Text\r\nSelect Case grade\r\n Case \"A\"\r\n Label1.Text=\"High Distinction\"\r\nCase \"A-\"\r\n Label1.Text=\"Distinction\"\r\nCase \"B\"\r\n Label1.Text=\"Credit\"\r\nCase \"C\"\r\n Label1.Text=\"Pass\"\r\nCase Else\r\n Label1.Text=\"Fail\"\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<h4>Example 10.2<\/h4>\n<p>In this example, you can use the keyword Is together with the comparison operators.<\/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 mark As Single\r\nmark = mrk.Text\r\nSelect Case mark\r\nCase Is &gt;= 85\r\nLabel1.Text= \"Excellence\"\r\nCase Is &gt;= 70\r\nLabel2.Text= \"Good\"\r\nCase Is &gt;= 60\r\nLabel3.Text = \"Above Average\"\r\nCase Is &gt;= 50\r\nLabel4.Text= \"Average\"\r\nCase Else\r\nLabel5.Text = \"Need to work harder\"\r\nEnd Select\r\n\r\nEnd Sub\r\n<\/pre>\n<h4><strong>Example 10.3<\/strong><\/h4>\n<p>Example 10.2 can be rewritten as follows:<\/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\n'Examination Marks\r\nDim mark As Single\r\n mark = Textbox1.Text\r\nSelect Case mark\r\nCase 0 to 49\r\n Label1.Text = \"Need to work harder\"\r\nCase 50 to 59\r\n Label1.Text = \"Average\" s\r\nCase 60 to 69\r\n Label1.Text= \"Above Average\"\r\nCase 70 to 84\r\n Label1.Text = \"Good\"\r\nCase 85 to 100\r\n Label1.Text= \"Excellence\"\r\nCase Else\r\n Label1.Text= \"Wrong entry, please reenter the mark\"\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<h4><strong>Example 10.4<\/strong><\/h4>\n<p>Grades in high school are usually presented with a single capital letter such as A, B, C, D or E. The grades can be computed as follow:<\/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\n'Examination Marks\r\nDim mark As Single\r\n mark = TextBox1.Text\r\nSelect Case mark\r\nCase 0 To 49\r\n Label1.Text = \"E\"\r\nCase 50 To 59\r\n Label1.Text = \"D\"\r\nCase 60 To 69\r\n Label1.Text = \"C\"\r\nCase 70 To 79\r\n Label1.Text = \"B\"\r\nCase 80 To 100\r\n Label1.Text = \"A\"\r\nCase Else\r\n Label1.Text = \"Error, please reenter the mark\"\r\nEnd Select\r\n\r\nEnd Sub\r\n<\/pre>\n<p>The output of Example 10.4<\/p>\n<p><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\" alt=\"\" style=\"width: auto ; max-width: 100%;height: auto\" \/><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- vb2010 responsive --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"2565700708\" data-ad-format=\"auto\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><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=\"..\/..\/index.php\/visual-basic-2010-lesson-9\/\">[Lesson 9]<\/a> <\/strong>&lt;&lt; <strong> <a href=\"..\/..\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt; <a href=\"..\/..\/index.php\/visual-basic-2010-lesson-11\/\">[Lesson 11]<\/a> <\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 9] &lt;&lt; [CONTENTS] &gt;&gt; [Lesson 11] In the previous lesson, we have learned the If&#8230;Then&#8230;Else control structure. In this lesson, you will learn another way to control the program flow in Visual Basic 2010, that is, the Select Case control structure. Select Case control structure is slightly different from the If&#8230;.Else&#8230;Then control structure. The &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-10\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2010 Lesson 10- Using Select Case<\/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-1086","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 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This Visual Basic 2010 lesson illustrated the usage of Select Case 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_Lesson10.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 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This Visual Basic 2010 lesson illustrated the usage of Select Case in Visual Basic 2010\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.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-24T11:04:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.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=\"2 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-10\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html\",\"name\":\"Visual Basic 2010 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\",\"datePublished\":\"2012-04-06T08:40:52+00:00\",\"dateModified\":\"2018-06-24T11:04:00+00:00\",\"description\":\"This Visual Basic 2010 lesson illustrated the usage of Select Case in Visual Basic 2010\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2010 Lesson 10- Using Select Case\"}]},{\"@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 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This Visual Basic 2010 lesson illustrated the usage of Select Case 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_Lesson10.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2010 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This Visual Basic 2010 lesson illustrated the usage of Select Case in Visual Basic 2010","og_url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.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-24T11:04:00+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-10\/","url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html","name":"Visual Basic 2010 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif","datePublished":"2012-04-06T08:40:52+00:00","dateModified":"2018-06-24T11:04:00+00:00","description":"This Visual Basic 2010 lesson illustrated the usage of Select Case in Visual Basic 2010","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#primaryimage","url":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif","contentUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_Lesson10.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2010 Lesson 10- Using Select Case"}]},{"@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\/1086","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=1086"}],"version-history":[{"count":67,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1086\/revisions"}],"predecessor-version":[{"id":13131,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1086\/revisions\/13131"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}