{"id":10025,"date":"2017-04-06T13:58:16","date_gmt":"2017-04-06T05:58:16","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=10025"},"modified":"2018-06-22T13:43:58","modified_gmt":"2018-06-22T05:43:58","slug":"visual-basic-2017-lesson-14-using-select-case","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-14-using-select-case\/","title":{"rendered":"Visual Basic 2017 Lesson 14: Using Select Case"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a title=\"visual basic 2017 tutorial lesson 13\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-13-using-else\/\">[Lesson 13]<\/a> &lt;&lt; <a title=\"visual basic 2015 tutorial\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-tutorial\/\">[Contents]<\/a> &gt;&gt;<a title=\"visual basic 2015 tutorial lesson 15\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-15-looping\/\"> [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 2017.\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 as using If\u2026Then..ElseIf statements will become too messy.<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=\"3393818013\"><\/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 Visual Basic 2017 is as follows:<\/p>\n<pre style=\"font-size: 110%;\">Select Case expression\r\nCase value1\r\nBlock VB statements\r\nCase value2\r\nBlock VB Statements\r\nCase value3\r\n.\r\n.\r\nCase Else\r\nBlock VB Statements\r\n\r\nEnd Select\r\n<\/pre>\n<h3>14.2 The usage of Select Case is shown in the following examples<\/h3>\n<h4>Example 14.1:\u00a0Examination Grades<\/h4>\n<p>In this example, the program will display a message associated with the grade entered by the user.<\/p>\n<h4><strong>The Code<\/strong><\/h4>\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<h4><strong>The Output <\/strong><\/h4>\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=\"3393818013\"><\/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\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\nEnd Sub\r\n<\/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=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 14.3<\/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\nDim mark As Single\r\nmark = Textbox1.Text\r\nSelect Case mark\r\nCase 0 to 49\r\nMsgBox(\u00a0\u201cNeed to work harder\u201d)\r\nCase 50 to 59\r\nMsgBox(\u00a0\u201cAverage\u201d )\r\nCase 60 to 69\r\nMsgBox(\u00a0\u201cAbove Average\u201d)\r\nCase 70 to 84\r\nMsgBox(\u00a0\u201cGood\u201d)\r\nCase 85 to 100\r\nMsgBox(\u201cExcellence\u201d)\r\nCase Else\r\nMsgBox(\u00a0\u201cWrong entry, please reenter the mark\u201d)\r\nEnd Select\r\nEnd Sub\r\n<\/pre>\n<h4>Example 14.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\u2018Examination Marks\r\nDim mark As Single\r\nmark = TextBox1.Text\r\nSelect Case mark\r\nCase 0 To 49\r\nLblGrade.Text = \u201cE\u201d\r\nCase 50 To 59\r\nLblGrade.Text = \u201cD\u201d\r\nCase 60 To 69\r\nLblGrade.Text = \u201cC\u201d\r\nCase 70 To 79\r\nLblGrade.Text = \u201cB\u201d\r\nCase 80 To 100\r\nLblGrade.Text = \u201cA\u201d\r\nCase Else\r\nLblGrade.Text = \u201cError, please re-enter 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\" \/><\/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=\"9961025909\"><\/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-2017-lesson-13-using-else\/\">[Lesson 13]<\/a> &lt;&lt; <a title=\"visual basic 2015 tutorial\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-tutorial\/\">[Contents]<\/a> &gt;&gt;<a title=\"visual basic 2015 tutorial lesson 15\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-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 shall learn how to use the\u00a0Select Case\u00a0control structure in\u00a0Visual Basic 2017.\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-2017-lesson-14-using-select-case\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2017 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-10025","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 2017 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"Learn how to write select case code in visual basic 2017\" \/>\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\/vb2017\/vb2017_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 2017 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"Learn how to write select case code in visual basic 2017\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_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-22T05:43:58+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-2017-lesson-14-using-select-case\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html\",\"name\":\"Visual Basic 2017 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\/vb2017\/vb2017_lesson14.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg\",\"datePublished\":\"2017-04-06T05:58:16+00:00\",\"dateModified\":\"2018-06-22T05:43:58+00:00\",\"description\":\"Learn how to write select case code in visual basic 2017\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_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\/vb2017\/vb2017_lesson14.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2017 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 2017 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Learn how to write select case code in visual basic 2017","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\/vb2017\/vb2017_lesson14.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2017 Lesson 14: Using Select Case - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"Learn how to write select case code in visual basic 2017","og_url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_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-22T05:43:58+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-2017-lesson-14-using-select-case\/","url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html","name":"Visual Basic 2017 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\/vb2017\/vb2017_lesson14.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/04\/vb2015_fig14.1.jpg","datePublished":"2017-04-06T05:58:16+00:00","dateModified":"2018-06-22T05:43:58+00:00","description":"Learn how to write select case code in visual basic 2017","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson14.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_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\/vb2017\/vb2017_lesson14.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2017 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\/10025","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=10025"}],"version-history":[{"count":16,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10025\/revisions"}],"predecessor-version":[{"id":12987,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10025\/revisions\/12987"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=10025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=10025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=10025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}