{"id":4560,"date":"2014-01-14T22:51:57","date_gmt":"2014-01-14T14:51:57","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=4560"},"modified":"2018-06-24T16:46:01","modified_gmt":"2018-06-24T08:46:01","slug":"visual-basic-2013-lesson-14-making-decisions-using-select-case","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-14-making-decisions-using-select-case\/","title":{"rendered":"Visual Basic 2013 Lesson 14: Using Select Case"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-13-making-decisions-using-if-then-else\/\">[Lesson 13]<\/a> &lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-15-looping\/\">[Lesson 15]<\/a><\/h4>\n<p>In this lesson, you will learn how to use the\u00a0<strong>Select Case<\/strong>\u00a0control structure in\u00a0Visual Basic 2013 \u00a0to control the program flow.<\/p>\n<p>The Select Case control structure is slightly different from the I&#8230;.then&#8230;Else control structure. The difference is that the Select Case control structure basically only make a decision on one expression or dimension. On the other hand, the If&#8230;Then&#8230;Else statement may evaluate only one expression, each If statement may also compute entirely different dimensions. Select Case is preferred when there exist multiple conditions as using If\u2026Then..ElseIf statements will become too complicated.<\/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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>14.1 The Select Case\u2026End Select Structure<\/h3>\n<p>The structure of the Select Case control structure in 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\n.\r\nCase Else\r\nBlock of one or more Statements\r\nEnd Select\r\n<\/pre>\n<h3>14.2 The usage of Select Case is shown in the following examples<\/h3>\n<p><strong>Example 14.1:<\/strong>\u00a0Examination Grades<\/p>\n<pre style=\"font-size: 110%;\">Dim grade As String\r\nPrivate Sub Compute_Click( )\r\ngrade=txtgrade.Text\r\nSelect Case grade\r\n Case \u201cA\u201d\r\n  Label1.Text=\u201dHigh Distinction\u201d\r\n Case \u201cA-\u201d\r\n  Label1.Text=\u201dDistinction\u201d\r\n Case \u201cB\u201d\r\n  Label1.Text=\u201dCredit\u201d\r\n Case \u201cC\u201d\r\n  Label1.Text=\u201dPass\u201d\r\n Case Else\r\n  Label1.Text=\u201dFail\u201d\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<p><strong>Example 14.2<\/strong><br \/>\nIn this example, you can use the keyword Is together with the comparison operators.Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\u2019Examination Marks<\/p>\n<pre style=\"font-size: 110%;\">Dim mark As Single\r\nmark = mrk.Text\r\nSelect Case mark\r\n Case Is &gt;= 85\r\n  Label1.Text= \u201cExcellence\u201d\r\n Case Is &gt;= 70\r\n  Label2.Text= \u201cGood\u201d\r\n Case Is &gt;= 60\r\n  Label3.Text = \u201cAbove Average\u201d\r\n Case Is &gt;= 50\r\n  Label4.Text= \u201cAverage\u201d\r\n Case Else\r\n  Label5.Text = \u201cNeed to work harder\u201d\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<p><strong>Example 14.3<\/strong><\/p>\n<p>Example 14.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\u2018Examination Marks\r\n\r\nDim mark As Single\r\nmark = Textbox1.Text\r\nSelect Case mark\r\n Case 0 to 49\r\n  Label1.Text = \u201cNeed to work harder\u201d\r\n Case 50 to 59\r\n  Label1.Text = \u201cAverage\u201d s\r\n Case 60 to 69\r\n  Label1.Text= \u201cAbove Average\u201d\r\n Case 70 to 84\r\n  Label1.Text = \u201cGood\u201d\r\n Case 85 to 100\r\n  Label1.Text= \u201cExcellence\u201d\r\n Case Else\r\n  Label1.Text= \u201cWrong entry, please reenter the mark\u201d\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<p><strong>Example 14.4<\/strong><\/p>\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<p>&nbsp;<\/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\u2018Examination Marks\r\nDim mark As Single\r\n mark = TextBox1.Text\r\nSelect Case mark\r\n Case 0 To 49\r\n  Label1.Text = \u201cE\u201d\r\n Case 50 To 59\r\n  Label1.Text = \u201cD\u201d\r\n Case 60 To 69\r\n  Label1.Text = \u201cC\u201d\r\n Case 70 To 79\r\n  Label1.Text = \u201cB\u201d\r\n Case 80 To 100\r\n  Label1.Text = \u201cA\u201d\r\n Case Else\r\n  Label1.Text = \u201cError, please reenter the mark\u201d\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<p>The output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\" alt=\"\" width=\"315\" height=\"300\" \/><strong>Figure 14.1<\/strong><\/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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/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=\"2306771905\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-13-making-decisions-using-if-then-else\/\">[Lesson 13]<\/a>\u00a0&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a>\u00a0&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-15-looping\/\">[Lesson 15]<\/a><\/h4>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 13] &lt;&lt; [Contents] &gt;&gt; [Lesson 15] In this lesson, you will learn how to use the\u00a0Select Case\u00a0control structure in\u00a0Visual Basic 2013 \u00a0to control the program flow. The Select Case control structure is slightly different from the I&#8230;.then&#8230;Else control structure. The difference is that the Select Case control structure basically only make a decision on &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-14-making-decisions-using-select-case\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2013 Lesson 14: 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-4560","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 2013 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This lesson explains how to use select case in visual basic 2013\" \/>\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\/vb2013\/vb2013_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 2013 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This lesson explains how to use select case in visual basic 2013\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_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=\"2018-06-24T08:46:01+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-2013-lesson-14-making-decisions-using-select-case\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html\",\"name\":\"Visual Basic 2013 Lesson 14: 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\/vb2013\/vb2013_Lesson14.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif\",\"datePublished\":\"2014-01-14T14:51:57+00:00\",\"dateModified\":\"2018-06-24T08:46:01+00:00\",\"description\":\"This lesson explains how to use select case in visual basic 2013\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.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\/vb2013\/vb2013_Lesson14.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2013 Lesson 14: 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 2013 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This lesson explains how to use select case in visual basic 2013","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\/vb2013\/vb2013_Lesson14.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2013 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This lesson explains how to use select case in visual basic 2013","og_url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_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":"2018-06-24T08:46:01+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-2013-lesson-14-making-decisions-using-select-case\/","url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html","name":"Visual Basic 2013 Lesson 14: 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\/vb2013\/vb2013_Lesson14.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_10.1.gif","datePublished":"2014-01-14T14:51:57+00:00","dateModified":"2018-06-24T08:46:01+00:00","description":"This lesson explains how to use select case in visual basic 2013","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson14.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\/vb2013\/vb2013_Lesson14.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2013 Lesson 14: 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\/4560","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=4560"}],"version-history":[{"count":41,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4560\/revisions"}],"predecessor-version":[{"id":13068,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4560\/revisions\/13068"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=4560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=4560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=4560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}