{"id":6417,"date":"2015-04-05T10:19:28","date_gmt":"2015-04-05T02:19:28","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=6417"},"modified":"2018-06-22T18:00:47","modified_gmt":"2018-06-22T10:00:47","slug":"visual-basic-2015-lesson-14-dealing-multiple-choices-using-select-case","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-14-dealing-multiple-choices-using-select-case\/","title":{"rendered":"Visual Basic 2015 Lesson 14:  Using Select Case"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a title=\"visual basic 2015 tutorial lesson 13\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-13-using-else\/\">[Lesson 13]<\/a> &lt;&lt; <a title=\"visual basic 2015 tutorial\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a> &gt;&gt;<a title=\"visual basic 2015 tutorial lesson 15\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-15-looping-repetitive-jobs\/\"> [Lesson 15]<\/a><\/h4>\n<p>In this lesson, you shall learn how to use the\u00a0<strong>Select Case<\/strong>\u00a0control structure in\u00a0Visual Basic 2015.\u00a0The Select Case control structure also involves decisions making but it slightly different from the If\u2026.ElseIf control structure . The If \u2026 Then&#8230;ElseIf statement control structure evaluates only one expression but each ElseIf statement computes different values for the expression. On the other hand, the Select Case control structure evaluates one expression for multiple values. Select Case is preferred when there exist multiple conditions.<br \/>\n<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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4><strong>14.1 The Select Case\u2026End Select Structure<\/strong><\/h4>\n<p>The structure of the Select Case control structure in Visual Basic 2015 is as follows:<\/p>\n<pre style=\"font-size: 110%;\">Select Case expressionCase value1\r\nStatements\r\nCase value2\r\nStatements\r\nCase value3\r\n.\r\n.\r\nCase Else\r\nStatements\r\nEnd Select\r\n<\/pre>\n<h4><strong>14.2 The usage of Select Case\u00a0<\/strong><\/h4>\n<h4><strong>Example 14.1:\u00a0Examination Grades<\/strong><\/h4>\n<p>In this example, the program will display a message associated with the grade entered by the user.<\/p>\n<p><strong>The Code<\/strong><\/p>\n<pre style=\"font-size: 110%;\">Private Sub BtnShow_Click(sender As Object, e As EventArgs) Handles BtnShow.Click\r\nDim grade As String\r\ngrade = TxtGrade.Text\r\nSelect Case grade\r\nCase \u201cA\u201d\r\nMsgBox(\u201dHigh Distinction\u201d)\r\nCase \u201cA-\u201d\r\nMsgBox(\u201dDistinction\u201d)\r\nCase \u201cB\u201d\r\nMsgBox(\u201dCredit\u201d)\r\nCase \u201cC\u201d\r\nMsgBox(\u201dPass\u201d)\r\nCase Else\r\nMsgBox(\u201dFail\u201d)End Select\r\nEnd Sub\r\n<\/pre>\n<p><strong>The Output <\/strong><\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6478\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\" alt=\"vb2015_fig14.1\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg 300w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1-150x150.jpg 150w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>\u00a0Figure 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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6479\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.2.jpg\" alt=\"vb2015_fig14.2\" width=\"154\" height=\"155\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.2.jpg 154w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.2-150x150.jpg 150w\" sizes=\"auto, (max-width: 154px) 100vw, 154px\" \/><\/a><\/p>\n<h4 style=\"text-align: center;\"><strong>Figure 14.2<\/strong><\/h4>\n<p>In this example, you can use the keyword <strong>Is<\/strong> together with the comparison operators to evaluate an expression.<\/p>\n<h4><strong>Example 14.2<\/strong><\/h4>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\u2019Examination Marks\r\n\r\nDim mark As Single\r\nmark = mrk.Text\r\nSelect Case mark\r\nCase Is &gt;= 85\r\nMsgBox(\u00a0\u201cExcellence\u201d)\r\nCase Is &gt;= 70\r\nMsgBox(\u00a0\u201cGood\u201d)\r\nCase Is &gt;= 60\r\nMsgBox(\u00a0\u201cAbove Average\u201d)\r\nCase Is &gt;= 50\r\nMsgBox(\u00a0\u201cAverage\u201d)\r\nCase Else\r\nMsgBox(\u00a0\u201cNeed to work harder\u201d)\r\nEnd Select\r\n\r\nEnd Sub\r\n<\/pre>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- VB2015 Responsive --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"1544369909\" data-ad-format=\"auto\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4><strong>Example 14.3<\/strong><\/h4>\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\r\n\u2018Examination Marks\r\n\r\nDim mark As Single\r\nmark = Textbox1.Text\r\nSelect Case mark\r\n\r\nCase 0 to 49\r\nMsgBox(\u00a0\u201cNeed to work harder\u201d)\r\n\r\nCase 50 to 59\r\nMsgBox(\u00a0\u201cAverage\u201d )\r\n\r\nCase 60 to 69\r\nMsgBox(\u00a0\u201cAbove Average\u201d)\r\n\r\nCase 70 to 84\r\nMsgBox(\u00a0\u201cGood\u201d)\r\n\r\nCase 85 to 100\r\nMsgBox(\u201cExcellence\u201d)\r\n\r\nCase Else\r\nMsgBox(\u00a0\u201cWrong entry, please reenter the mark\u201d)\r\n\r\nEnd Select\r\n\r\nEnd Sub\r\n<\/pre>\n<h4><strong>Example 14.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\r\n\u2018Examination Marks\r\n\r\nDim mark As Single\r\n\r\nmark = TextBox1.Text\r\n\r\nSelect Case mark\r\n\r\nCase 0 To 49\r\nLblGrade.Text = \u201cE\u201d\r\n\r\nCase 50 To 59\r\n\r\nLblGrade.Text = \u201cD\u201d\r\nCase 60 To 69\r\n\r\nLblGrade.Text = \u201cC\u201d\r\nCase 70 To 79\r\n\r\nLblGrade.Text = \u201cB\u201d\r\n\r\nCase 80 To 100\r\nLblGrade.Text = \u201cA\u201d\r\n\r\nCase Else\r\nLblGrade.Text = \u201cError, please re-enter the mark\u201d\r\n\r\nEnd Select\r\n\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\" \/><\/p>\n<p><strong>Figure 14.3<\/strong><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=\"1492877908\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><a title=\"visual basic 2015 tutorial lesson 13\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-13-using-else\/\">[Lesson 13]<\/a> &lt;&lt; <a title=\"visual basic 2015 tutorial\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a> &gt;&gt;<a title=\"visual basic 2015 tutorial lesson 15\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-15-looping-repetitive-jobs\/\"> [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 shall learn how to use the\u00a0Select Case\u00a0control structure in\u00a0Visual Basic 2015.\u00a0The Select Case control structure also involves decisions making but it slightly different from the If\u2026.ElseIf control structure . The If \u2026 Then&#8230;ElseIf statement control structure evaluates only one expression but each ElseIf statement &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-14-dealing-multiple-choices-using-select-case\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2015 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-6417","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 2015 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article illustrate how to write code for select case in visual basic 2015\" \/>\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\/vb2015\/vb2015_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 2015 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article illustrate how to write code for select case in visual basic 2015\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_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-22T10:00:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\" \/>\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-2015-lesson-14-dealing-multiple-choices-using-select-case\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html\",\"name\":\"Visual Basic 2015 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\/vb2015\/vb2015_Lesson14.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\",\"datePublished\":\"2015-04-05T02:19:28+00:00\",\"dateModified\":\"2018-06-22T10:00:47+00:00\",\"description\":\"This article illustrate how to write code for select case in visual basic 2015\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2015 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 2015 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article illustrate how to write code for select case in visual basic 2015","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\/vb2015\/vb2015_Lesson14.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2015 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article illustrate how to write code for select case in visual basic 2015","og_url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_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-22T10:00:47+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg","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-2015-lesson-14-dealing-multiple-choices-using-select-case\/","url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html","name":"Visual Basic 2015 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\/vb2015\/vb2015_Lesson14.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg","datePublished":"2015-04-05T02:19:28+00:00","dateModified":"2018-06-22T10:00:47+00:00","description":"This article illustrate how to write code for select case in visual basic 2015","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_Lesson14.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2015 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\/6417","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=6417"}],"version-history":[{"count":40,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/6417\/revisions"}],"predecessor-version":[{"id":13029,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/6417\/revisions\/13029"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=6417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=6417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=6417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}