{"id":2350,"date":"2013-02-12T15:56:39","date_gmt":"2013-02-12T07:56:39","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T17:57:21","modified_gmt":"2018-06-24T09:57:21","slug":"visual-basic-2012-lesson-10-using-select-case","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-10-using-select-case\/","title":{"rendered":"Visual Basic 2012 Lesson 10- Using Select Case"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-9-using-if-then-else\/\">[Lesson 9]<\/a> <\/strong>&lt;&lt; <strong> <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-11-looping\/\">[Lesson 11]<\/a> <\/strong><\/h4>\n<p>In this lesson, you will learn how to use the\u00a0<strong>Select Case<\/strong>\u00a0control structure in\u00a0VB2012 \u00a0to control the program flow. The Select Case control structure is slightly different from the If&#8230;.ElseIf control structure .The difference is that the Select Case control structure basically only make a decision on one expression or dimension (for example the examination grade) while the If &#8230;ElseIf statement control structure may evaluate only one expression, each If&#8230;.ElseIf statement may also compute entirely different dimensions. Select Case is preferred when there exist multiple conditions as using If&#8230;Then..ElseIf statements will become too messy.<\/p>\n<h3>10.1 The Select Case Structure<\/h3>\n<p>The syntax of the Select Case control structure in Visual Basic 2012 is as follows:<\/p>\n<pre style=\"font-size: 110%;\">Select Case test expressionCase expression list 1\r\nBlock of one or more statements\r\nCase expression list 2\r\nBlock of one or more Statements\r\nCase expression list 3\r\n.\r\nCase Else\r\nBlock of one or more Statements\r\nEnd Select\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>10.2 The usage of Select Case is shown in the following examples<\/h3>\n<h4>Example 10.1<\/h4>\n<pre style=\"font-size: 110%;\">' Examination Grades\r\nDim grade As String\r\nPrivate Sub Compute_Click( )\r\n grade=txtgrade.Text\r\n Select Case grade\r\n  Case \"A\"\r\n   Label1.Text=\"High Distinction\"\r\n Case \"A-\"\r\n  Label1.Text=\"Distinction\"\r\n Case \"B\"\r\n  Label1.Text=\"Credit\"\r\n Case \"C\"\r\n  Label1.Text=\"Pass\"\r\n Case Else\r\n  Label1.Text=\"Fail\"\r\n End Select<\/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'Examination MarksDim mark As Single\r\n mark = mrk.Text\r\n Select Case mark\r\n  Case Is &gt;= 85\r\n  Label1.Text= \"Excellence\"\r\n  Case Is &gt;= 70\r\n  Label2.Text= \"Good\"\r\n Case Is &gt;= 60\r\n  Label3.Text = \"Above Average\"\r\n Case Is &gt;= 50\r\n  Label4.Text= \"Average\"\r\n Case Else\r\n  Label5.Text = \"Need to work harder\"\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<h4>Example 10.3<\/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\r\n'Examination Marks\r\nDim mark As Single\r\n mark = Textbox1.Text\r\n Select Case mark\r\n  Case 0 to 49\r\n   Label1.Text = \"Need to work harder\"\r\n  Case 50 to 59\r\n  Label1.Text = \"Average\" s\r\n Case 60 to 69\r\n  Label1.Text= \"Above Average\"\r\n Case 70 to 84\r\n  Label1.Text = \"Good\"\r\n Case 85 to 100\r\n  Label1.Text= \"Excellence\"\r\n Case Else\r\n  Label1.Text= \"Wrong entry, please reenter the mark\"\r\nEnd Select\r\n\r\nEnd Sub\r\n<\/pre>\n<h4>Example 10.4<\/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\r\n'Examination Marks\r\nDim mark As Single\r\nmark = TextBox1.Text\r\nSelect Case mark\r\n Case 0 To 49\r\n  Label1.Text = \"E\"\r\n Case 50 To 59\r\n  Label1.Text = \"D\"\r\n Case 60 To 69\r\n  Label1.Text = \"C\"\r\n Case 70 To 79\r\n  Label1.Text = \"B\"\r\n Case 80 To 100\r\n  Label1.Text = \"A\"\r\n Case Else\r\n  Label1.Text = \"Error, please reenter the mark\"\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<p>The output of Example 10.4<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\" alt=\"Visual Basic 2012 \" width=\"315\" height=\"300\" \/><br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"1777484012\"><\/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=\"6598395509\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-9-using-if-then-else\/\">[Lesson 9]<\/a> <\/strong>&lt;&lt; <strong> <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-11-looping\/\">[Lesson 11]<\/a> <\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 9] &lt;&lt; [CONTENTS] &gt;&gt; [Lesson 11] In this lesson, you will learn how to use the\u00a0Select Case\u00a0control structure in\u00a0VB2012 \u00a0to control the program flow. The Select Case control structure is slightly different from the If&#8230;.ElseIf control structure .The difference is that the Select Case control structure basically only make a decision on one expression &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-10-using-select-case\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2012 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-2350","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 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure 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_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 2012 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure in Visual Basic 2012\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_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-24T09:57:21+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-2012-lesson-10-using-select-case\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html\",\"name\":\"Visual Basic 2012 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\/vb2012\/vb2012_Lesson10.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\",\"datePublished\":\"2013-02-12T07:56:39+00:00\",\"dateModified\":\"2018-06-24T09:57:21+00:00\",\"description\":\"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure in Visual Basic 2012\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_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\/vb2012\/vb2012_Lesson10.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2012 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 2012 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure 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_Lesson10.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2012 Lesson 10- Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure in Visual Basic 2012","og_url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_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-24T09:57:21+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-2012-lesson-10-using-select-case\/","url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html","name":"Visual Basic 2012 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\/vb2012\/vb2012_Lesson10.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif","datePublished":"2013-02-12T07:56:39+00:00","dateModified":"2018-06-24T09:57:21+00:00","description":"This is Visual Basic 2012 tutorial lesson 10 that teaches the method of using the Select Case control structure in Visual Basic 2012","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2012\/vb2012_Lesson10.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_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\/vb2012\/vb2012_Lesson10.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2012 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\/2350","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=2350"}],"version-history":[{"count":46,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2350\/revisions"}],"predecessor-version":[{"id":13100,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2350\/revisions\/13100"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=2350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=2350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}